tags:

views:

45

answers:

3

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: 

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 :)

Tim
A: 

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'.
Alexander.Plutov
thanks but it is not the ouput :(
devzone
A: 

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.

Michael