PHP Time Since Function?
10,039
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');
Author by
wesbos
Author of Sublime Text Book HTML5, JavaScript, Sublime Text, Node.js, CSS3 and all good things.
Updated on June 28, 2022Comments
-
wesbos almost 2 years
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.