Skip to content

Instantly share code, notes, and snippets.

@dave-jay
Created November 3, 2014 14:13
Show Gist options
  • Save dave-jay/0186c38061b1e04a50c7 to your computer and use it in GitHub Desktop.
Save dave-jay/0186c38061b1e04a50c7 to your computer and use it in GitHub Desktop.
<?php
function _dateDiff($date1, $date2) {
$time = strtotime($date1);
$time2 = strtotime($date2);
$diff = $time - $time2;
$return = array();
$days = $diff / (60 * 60 * 24 );
$whole = floor($days);
$hours = intval(($days - $whole)*24);
$return['days'] = intval($days);
$return['hours'] = $hours;
return $return;;
}
_dateDiff("2014-11-05 11:00:00", "2014-11-01 13:00:00"));
# returns:
/*
...Array
(
[days] => 3
[hours] => 23
)
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment