|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-04-24 15:54 UTC] heiglandreas@php.net
-Status: Open
+Status: Duplicate
[2017-04-24 15:54 UTC] heiglandreas@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
Description: ------------ When calculating the number of months between the 1st of februari and the 1st of march I espect it to return 1 month but it returns 0. I first tought this had to do with the leap year but that doesn't have anything to do with it becouse it also happens for 2015. Test script: --------------- <?php $first = new \DateTime('2016-02-01 00:00:00', new \DateTimeZone('Europe/Amsterdam')); $second = new \DateTime('2016-03-01 00:00:00', new \DateTimeZone('Europe/Amsterdam')); $diff = $first->diff($second); echo $diff->format('%m') . PHP_EOL; // Expect: 1, got 0 $second->modify('+1 month'); $diff2 = $first->diff($second); echo $diff2->format('%m') . PHP_EOL; // Expect: 2, got 2