Hello in my database date / time are in this format
2010-06-01T18:20:25+0000
I\'d like to echo that out to time passed since that date / t
function time_ago($timestamp, $granularity = 2) {
$timestamp = time() - $timestamp;
$units = array('1 year|%d years' => 31536000,
'1 week|%d weeks' => 604800,
'1 day|%d days' => 86400,
'1 hour|%d hours' => 3600,
'1 min|%d mins' => 60,
'1 sec|%d secs' => 1
);
$output = '';
foreach ($units as $key => $value) {
$key = explode('|', $key);
if ($timestamp >= $value) {
$pluralized = floor($timestamp / $value) > 1 ?
sprintf($key[1], floor($timestamp / $value)) :
$key[0];
$output .= ($output ? ' ' : '') . $pluralized;
$timestamp %= $value;
$granularity--;
}
if ($granularity == 0) {
break;
}
}
return $output ? $output : "Just now";
}
This should be close.
Edit: added this line: $timestamp = time() - $timestamp;