Created
March 23, 2013 11:52
-
-
Save karlgroves/5227438 to your computer and use it in GitHub Desktop.
PHP function to get difference between two times
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
/** | |
* returns the difference between two times | |
* @param string $start the starting time for comparison | |
* @param string $end the ending time for comparison | |
* @return array an array is populated with the time difference | |
*/ | |
function timediff($start, $end) { | |
$timediff = $end - $start; | |
$days = intval($timediff / 86400); | |
$remain = $timediff % 86400; | |
$hours = intval($remain / 3600); | |
$remain = $remain % 3600; | |
$mins = intval($remain / 60); | |
$secs = $remain % 60; | |
$output = array(); | |
$output['days'] = $days; | |
$output['hours'] = $hours; | |
$output['minutes'] = $minutes; | |
$output['seconds'] = $seconds; | |
$output['full'] = $days . 'days ' . $hours . 'hrs ' . $mins . 'mins ' . $secs . 'sec '; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment