Skip to content

Instantly share code, notes, and snippets.

@karlgroves
Created March 23, 2013 11:52
Show Gist options
  • Save karlgroves/5227438 to your computer and use it in GitHub Desktop.
Save karlgroves/5227438 to your computer and use it in GitHub Desktop.
PHP function to get difference between two times
/**
* 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