Skip to content

Instantly share code, notes, and snippets.

@jorgeguberte
Created October 7, 2011 16:06
Show Gist options
  • Save jorgeguberte/1270672 to your computer and use it in GitHub Desktop.
Save jorgeguberte/1270672 to your computer and use it in GitHub Desktop.
date_diff php workaround
/*
* DateTime::diff on PHP has a bug on Windows systems where it always outputs 6015. Here's a workaround]
* that i found on http://acme-tech.net/blog/2010/10/12/php-datetimediff-returns-6015/
*/
function dateDiff($dt1, $dt2, $timeZone = 'GMT') {
$tZone = new DateTimeZone($timeZone);
$dt1 = new DateTime($dt1, $tZone);
$dt2 = new DateTime($dt2, $tZone);
$ts1 = $dt1->format('Y-m-d');
$ts2 = $dt2->format('Y-m-d');
$diff = abs(strtotime($ts1)-strtotime($ts2));
$diff/= 3600*24;
return $diff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment