Skip to content

Instantly share code, notes, and snippets.

@shahril96
Created October 7, 2013 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahril96/6868141 to your computer and use it in GitHub Desktop.
Save shahril96/6868141 to your computer and use it in GitHub Desktop.
24-hour format range to minutes
<?php
echo twentyfourminute('2000', '2200'); // input in string
function twentyfourminute($first, $end){
$total = 0;
if($first[0] == '0') $first = substr($first, 1);
if($end[0] == '0') $end = substr($end, 1);
if((intval($first) % 100) != 0){
$total += 60 - (intval($first) % 100);
$first -= (intval($first) % 100) - 100;
}
if((intval($end) % 100) != 0){
$total += intval($end) % 100;
$end -= intval($end) % 100;
}
$total += (($end/100) - ($first/100)) * 60;
return $total;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment