Skip to content

Instantly share code, notes, and snippets.

@dave-jay
Created November 3, 2014 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave-jay/5e41b289ef239527b463 to your computer and use it in GitHub Desktop.
Save dave-jay/5e41b289ef239527b463 to your computer and use it in GitHub Desktop.
<?php
function _dateDiff($date1, $date2) {
$time1 = new DateTime($date1);
$time2 = new DateTime($date2);
$interval = $time1->diff($time2);
$return = array();
$return['days'] = $interval->days;
$return['hours'] = $interval->h;
$return['interval'] = $interval->invert == "-1" ? "negative" : "positive";
return $return;
}
$diff = _dateDiff("2014-11-02 11:00:00","2014-11-01 13:00:00"));
# if first date is bigger than interval = positive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment