3

I'm looking for a function that will take in a unix timestamp and output something like this:

4 years, 3 months, 12 days, 4 hours and 23 minutes ago.

Everything I have found has been pretty dates that just say something similar to "5 years ago" which I don't want.

hakre
  • 193,403
  • 52
  • 435
  • 836
wesbos
  • 25,839
  • 30
  • 106
  • 143
  • @Patrick: Not truly duplicate. Over there there is no implementation except for pointing out to some urls :) – Sarfraz Feb 15 '11 at 22:03

1 Answers1

24

You want DateInterval's format method:

$date = new \DateTime();
$date->setTimestamp($timestamp);
$interval = $date->diff(new \DateTime('now'));
echo $interval->format('%y years, %m months, %d days, %h hours and %i minutes ago');
rojoca
  • 11,040
  • 4
  • 45
  • 46