i have a span tag which has array data like
<?php echo " <span >".$comments_array[$j]['posted_time']."</span> "; ?>
and it echo's time of the comment as 2014-04-11 05:07:52
now i have a function that display the time in the format of x hrs ago,
below is the function
define("SECOND", 1);
define("MINUTE", 60 * SECOND);
define("HOUR", 60 * MINUTE);
define("DAY", 24 * HOUR);
define("MONTH", 30 * DAY);
function relTime($time)
{
$now = new DateTime;
$dateObj = new DateTime($dt);
$diff = (array) $now->diff($dateObj);
$diff['w'] = floor($diff['d'] / 7);
$diff['d'] -= $diff['w'] * 7;
$tokens = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second'
);
foreach ($tokens as $unit => &$text)
{
if ($diff[$unit])
{
$text = sprintf(
'%s %s%s',
$diff[$unit], $text, ($diff[$unit] > 1 ? 's' : '')
);
}
else
{
unset($tokens[$unit]);
}
}
return array_shift($tokens);
}
now how can i call that function and echo that time in desired format
help me please