Can someone please help me, the code below returns a timestamp to look like this
1 days 2 hours 38 minutes 31 seconds ago
can you help me make it not show the seconds so the above would look like
1 days 2 hours 38 minutes ago
<?PHP
function duration($timestamp) {
$years = floor($timestamp / (60 * 60 * 24 * 365));
$timestamp %= 60 * 60 * 24 * 365;
$weeks = floor($timestamp / (60 * 60 * 24 * 7));
$timestamp %= 60 * 60 * 24 * 7;
$days = floor($timestamp / (60 * 60 * 24));
$timestamp %= 60 * 60 * 24;
$hrs = floor($timestamp / (60 * 60));
$timestamp %= 60 * 60;
$mins = floor($timestamp / 60);
$secs = $timestamp % 60;
$str = "";
if ($years >= 1) {
$str .= "{$years} years ";
}
if ($weeks >= 1) {
$str .= "{$weeks} weeks ";
}
if ($days >= 1) {
$str .= "{$days} days ";
}
if ($hrs >= 1) {
$str .= "{$hrs} hours ";
}
if ($mins >= 1) {
$str .= "{$mins} minutes ";
}
if ($secs >= 1) {
$str .= "{$secs} seconds ";
}
return $str;
}
// $row['date'] is a datetime stamp from mysql
//variables for time duration
$year = substr($row['date'], 0, 4);
$month = substr($row['date'], 5, 2);
$day = substr($row['date'], 8, 2);
$hour = substr($row['date'], 11, 2);
$minute = substr($row['date'], 14, 2);
$second = substr($row['date'], 17, 2);
$ts = mktime($hour, $minute, $second, $month, $day, $year);
$ts = $time - $ts;
//shows time like this 1 days 2 hours 38 minutes 31 seconds ago
echo duration($ts);
?>