Skip to content

Instantly share code, notes, and snippets.

@jeremejazz
Created June 3, 2013 05:31
Show Gist options
  • Save jeremejazz/5696254 to your computer and use it in GitHub Desktop.
Save jeremejazz/5696254 to your computer and use it in GitHub Desktop.
used to convert Hours:Mins to minutes and the other way around
<?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