0

Possible Duplicate:
How do I calculate relative time?
How to display “12 minutes ago” etc in a PHP webpage?

I have date formats like this:

2011-09-10 12:00:00
2011-09-12 11:02:05
2011-09-12

I want to create a function that will get a date and will output something like this ?

5 minutes ago
2 hours ago
today
yesterday

and show date if date is far away.

Is there any related function in php or any free already written library.

Thanks

Community
  • 1
  • 1
Student
  • 1,843
  • 9
  • 37
  • 50
  • Really... see the question I linked to there, the first answer is the solution you're after. – Chris Baker Sep 12 '11 at 18:59
  • Check out http://php.net/manual/en/datetime.diff.php. Wrap some conditionals around that to figure out what unit to display and you're done. – Marc B Sep 12 '11 at 19:00
  • 1
    This has been answered dozen of times on SO: http://stackoverflow.com/questions/4707875/php-relative-time-problems, http://stackoverflow.com/questions/2643113/convert-2010-04-16-163000-to-tomorrow-afternoon/2643137, http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time (logic) – Jason McCreary Sep 12 '11 at 19:01

0 Answers0