How to get how many hour minute seconds laps on message on php mysql?
How to get how many hour minute seconds laps开发者_运维问答 on message on php mysql?
like
23 seconds ago 1 minute ago
is this possible?
A really simple way is using the jQuery plugin timeago http://timeago.yarp.com/
The neat thing about it is, that it updates the entries while viewing the page :)
In db table create field time
INT(10). Insert in this filed php time()
.
In script check diff:
$diff = time() - $time_from_db;
echo $diff . 'seconds ago'.
If you did want to have the data fed from the database you could write SQL like this:
SELECT FLOOR((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(your_date)) / 86400) as days FROM your_table
(MySQL example)
You could should then repeat for hours, minutes etc. subtracting the reminder.
From your result you would have $result['days']
available.
This said I would go for the timeago solution mentioned by Tim. But it is hard to say not knowing your application.
精彩评论