PHP: producing relative date/time from timestamps

Posted by KeyStroke on Stack Overflow See other posts from Stack Overflow or by KeyStroke
Published on 2010-04-22T11:55:46Z Indexed on 2010/04/22 12:03 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

Hi,

I'm basically trying to convert a Unix timestamp (the time() function) to a relative date/time that's both compatible with past and future date. So outputs could be:

2 weeks ago

1 hour and 60 minutes ago

15 minutes and 54 seconds ago

after 10 minutes and 15 seconds

First I tried to code this, but made a huge unmaintainable function, and then I searched the internet for a couple of hours, yet all I can find are scripts that produce only one part of the time (e.h: "1 hour ago" without the minutes).

Do you have a script that already does this? If so, I'd really appreciate if you could share it.

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about time