PHP's DateTime::Diff gets it wrong?

You're right, PHP currently doesn't handle DST transitions...

Bug reports #51051 (still open) and #55253 (fixed in PHP 5.3.9) describe the problems you're having.

Daniel Convissor has written an RFC trying to address the issue a while back but the change-logs don't suggest this has been addressed. I was hoping this would fixed in 5.4 but I don't see any evidence it has been.

When/if it is implemented, it looks like you'll have to append "DST" or "ST" to the time string.

Best practice is to do all your date calculations in UTC, which avoids this problem.

This DST best practices post is very informative too.


Do enjoy this list of related bugs in the PHP DateTime class, most of which have been open for 2+ years:

  • https://bugs.php.net/bug.php?id=40743
  • https://bugs.php.net/bug.php?id=49914
  • https://bugs.php.net/bug.php?id=51051
  • https://bugs.php.net/bug.php?id=51557
  • https://bugs.php.net/bug.php?id=52480
  • https://bugs.php.net/bug.php?id=54340
  • https://bugs.php.net/bug.php?id=54655
  • https://bugs.php.net/bug.php?id=55253
  • https://bugs.php.net/bug.php?id=60873
  • https://bugs.php.net/bug.php?id=60960
  • https://bugs.php.net/bug.php?id=61022
  • https://bugs.php.net/bug.php?id=61311
  • https://bugs.php.net/bug.php?id=61530
  • https://bugs.php.net/bug.php?id=61955