Convert Time String to Decimal Hours PHP [closed]

A fairly dumb conversion from the top of my head, using explode by colon:

<?php 

$hms = "2:12:0";
$decimalHours = decimalHours($hms);

function decimalHours($time)
{
    $hms = explode(":", $time);
    return ($hms[0] + ($hms[1]/60) + ($hms[2]/3600));
}

echo $decimalHours;

?>

Leave a Comment