Page 1 of 1

Show elapsed time since record created?

Posted: Fri Apr 25, 2008 10:38 am
by rcoy
I'm having a difficult time finding how to do this. I have people posting messages on my site and instead of showing the date they posted I would like to show how many minutes, or hours, or days since they posted. I've seen this on sites like twitter. I'm using PHP 5 and a MySQL database and new records are current time stamped. Thanks in advance for any help you can offer.

R. Coy

Re: Show elapsed time since record created?

Posted: Fri Apr 25, 2008 10:55 am
by aceconcepts
Use strtotime() to compare the time difference between the two times (dates).

Re: Show elapsed time since record created?

Posted: Fri Apr 25, 2008 10:56 am
by onion2k
In your SQL where you fetch the record put in something like..

Code: Select all

NOW() - `myTimestampField` AS seconds_since_posting
That'll give you a column called 'seconds_since_posting' that contains, well, the number of seconds since the post was posted. Then you just need to convert that into minutes, hours, days, etc. That's just a bit of division.