PHP: convert seconds to minutes and hours

Viewed 10793

I would like to convert a certain number of seconds to minutes and even hours. But i don't want to write an if clause for every minute and hour etc. ...

How can I do that in the easiest way, and with easiest I mean shortest. ;)

PHP:

$countholen = mysqli_fetch_array(mysqli_query($db, "
SELECT * FROM `blablabla` WHERE `blabla` = 'bla'
"));
$countholenfetch = $countholen["count"];
if ($countholenfetch <= 60){
    $count = $countholenfetch . " sec";
}
if ($countholenfetch > 60){
    $countholenfetch = $countholenfetch - 60;
    $count = "1 min" . " + " . $countholenfetch . " sec";
}
//...if clause with 120, 180, 240 etc. instead of 60 till 3600 and another if clause in an if clause...
echo $count;
2 Answers
Related