Created
June 3, 2013 05:31
-
-
Save jeremejazz/5696254 to your computer and use it in GitHub Desktop.
used to convert Hours:Mins to minutes and the other way around
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function convertMinsToHours($time, $format = '%d:%s') { | |
settype($time, 'integer'); | |
if ($time < 0 || $time >= 1440) { | |
return; | |
} | |
$hours = floor($time/60); | |
$minutes = $time%60; | |
if ($minutes < 10) { | |
$minutes = '0' . $minutes; | |
} | |
return sprintf($format, $hours, $minutes); | |
} | |
function convertHoursToMinutes($hours) | |
{ | |
$minutes = 0; | |
if (strpos($hours, ':') !== false) | |
{ | |
// Split hours and minutes. | |
list($hours, $minutes) = explode(':', $hours); | |
} | |
return $hours * 60 + $minutes; | |
} | |
//echo convertHoursToMinutes('1:03'); // will output 63 | |
//echo convertHoursToMinutes(63); // will output 103 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment