How to convert hours to minutes in PHP

1 Answer

0 votes
function hours2minutes($hours) { 
    $t = explode(".", $hours); 
    $h = $t[0]; 
    if (isset($t[1])) 
        $m = $t[1]; 
    else
        $m = "00"; 
    $mn = ($h * 60) + $m; 
     
    return $mn; 
} 
 
echo hours2minutes("2.30"); 
echo "\n";
echo hours2minutes("2.35"); 
echo "\n";
echo hours2minutes("5"); 



/*
run:

150
155
300

*/


answered Sep 1, 2014 by avibootz
edited Apr 16, 2025 by avibootz

Related questions

...