Created
October 7, 2011 16:06
-
-
Save jorgeguberte/1270672 to your computer and use it in GitHub Desktop.
date_diff php workaround
This file contains hidden or 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
/* | |
* 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