Quote (erasko @ Tue, Feb 24 2009, 07:13am)
whats the code looks like when I only want to show "...minutes ago"?
call it as $lastplayed
Code
$lastaction = (int)$data->lastaction;
$time1 = time() - $lastaction;
$lastplayed = sec2hms($time1);
function sec2hms ($sec, $padHours = false)
{
$days = intval(intval($sec) / 86400);
$hours = intval(($sec / 3600) % 24);
$minutes = intval(($sec / 60) % 60);
if ($days > 0) {
$hms = $days. ' days, ';
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ' hours ago'
: $hours. ' hours ago';
} else {
$hms = "";
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ' hours, '
: $hours. ' hours, ';
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ' minutes ago';
}
return $hms;
}