Skip to content

Instantly share code, notes, and snippets.

@tamboer
Created August 26, 2013 13:34
Show Gist options
  • Select an option

  • Save tamboer/6341468 to your computer and use it in GitHub Desktop.

Select an option

Save tamboer/6341468 to your computer and use it in GitHub Desktop.
time to decimal function
protected function _timeToDecimal($time){
list($hours,$minutes) = array_pad(explode(':',$time, 2), 2, null);
if(is_null($minutes)) $minutes = '00';
if(strstr($hours, '-')){
$negative=true;
$hours = 0 - $hours;
}else{
$negative= false;
}
$h = $hours;
$min = number_format($minutes) / 60;
$result = number_format($h + $min,3);
if($negative === true)$result = -1 * abs($result);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment