Pretty sure this is from Allied Modders, I think AMX Mod X, I just converted it to PHP a long time ago. Returns seconds into a string that is nice and readable.
<?php
class Time {
const SECONDS_IN_MINUTE = 60;
const SECONDS_IN_HOUR = 3600;
const SECONDS_IN_DAY = 86400;
const SECONDS_IN_WEEK = 604800;
public static function getTimeLen($s) {
if ($s > 0) {
$w = $d = $h = $m = 0; $element = array();
$w = round($s / self::SECONDS_IN_WEEK);
if ($w > 0) $element[] = sprintf('%d %s', $w, ($w == 1) ? 'week' : 'weeks');
$s -= $w * self::SECONDS_IN_WEEK;
$d = round($s / self::SECONDS_IN_DAY);
if ($d > 0) $element[] = sprintf('%d %s', $d, ($d == 1) ? 'day' : 'days');
$s -= $d * self::SECONDS_IN_DAY;
$h = round($s / self::SECONDS_IN_HOUR);
if ($h > 0) $element[] = sprintf('%d %s', $h, ($h == 1) ? 'hour' : 'hours');
$s -= $h * self::SECONDS_IN_HOUR;
$m = round($s / self::SECONDS_IN_MINUTE);
if ($m > 0) $element[] = sprintf('%d %s', $m, ($m == 1) ? 'minute' : 'minutes');
$s -= $m * self::SECONDS_IN_MINUTE;
if ($s > 0) $element[] = sprintf('%d %s', $s, ($s == 1) ? 'second' : 'seconds');
switch(count($element)) {
case 1: return sprintf("%s", $element[0]);
case 2: return sprintf("%s & %s", $element[0], $element[1]);
case 3: return sprintf("%s, %s & %s", $element[0], $element[1], $element[2]);
case 4: return sprintf("%s, %s, %s & %s", $element[0], $element[1], $element[2], $element[3]);
case 5: return sprintf("%s, %s, %s, %s & %s", $element[0], $element[1], $element[2], $element[3], $element[4]);
}
}
}
}
?>