views:

179

answers:

2

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.

+1  A: 

You can use DateTime::diff for get the diffrence between 2 DateTime objects, documentation you can find here:

http://pl.php.net/manual/en/datetime.diff.php

Svisstack
umm...how is that related to my question?
KeyStroke
A: 

This function gives you "1 hour ago" or "Tomorrow" like results between 'now' and 'specific timestamp'.

http://pastie.org/929569

Osman Üngür
but that only returns the hours with the minutes (for example), right?
KeyStroke
ok this ? http://pastie.org/929624
Osman Üngür