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
  • 184,866
  • 48
  • 414
  • 792
wesbos
  • 25,091
  • 29
  • 101
  • 142
  • @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
  • 10,842
  • 4
  • 43
  • 46