Convert minutes to hours and minutes or seconds to minutes and seconds

If you wish to convert minutes to hours and minutes display or convert minutes to minutes and second display here is a super useful function to do so:

function convertTo($time, $format = '%02d:%02d') {
    if ($time < 1) {
        return;
    }
    $hours = floor($time / 60);
    $minutes = ($time % 60);
    return sprintf($format, $hours, $minutes); // this also will return fine for converting minutes to minutes:seconds
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

tutorials