Reputation: 897
I have a time string which looks like this
2011-06-11T08:51:51Z
I'm not sure what this time format is, but I know it's not pretty to look at. Could someone help me convert it to "* hours ago" format
Upvotes: 2
Views: 3218
Reputation: 28160
In PHP 5.3, you can use DateInterval:
$date = new DateTime('2011-06-11T08:51:51Z');
$now = new DateTime();
$diff = $now->diff($date);
echo $diff->format('h');
Upvotes: 4
Reputation: 9671
$tstamp = strtotime('2011-06-11T08:51:51Z');
will give you the timestamp, calculate the number of hours like that:
$hours = floor((time() - $stamp()) / 3600);
Upvotes: 3
Reputation: 23713
I would do this:
$timestamp = strtotime($time_to_convert);
$actual_timestamp = time();
$dif_timestampm = $actual_timestamp - $timestamp;
$hours = $dif_timestampm / 3600;
Upvotes: 0
Reputation: 1612
First thing you need to do is convert it into a number (strtotime()), then compare it to the current time (time()) and finally divide the result by 3600 (the number of seconds in an hour).
Upvotes: 0