|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesbug-datetime-diff-calculations (last revision 2015-07-24 09:51 UTC by php at tul dot io)Pull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2015-07-24 10:33 UTC] derick@php.net
-Status: Open
+Status: Suspended
-Assigned To:
+Assigned To: derick
[2015-07-24 10:33 UTC] derick@php.net
[2022-10-19 15:26 UTC] derick@php.net
-Status: Suspended
+Status: Not a bug
[2022-10-19 15:26 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 15:00:01 2025 UTC |
Description: ------------ DateTime::diff() reports the wrong number of days and months when not in an inverted order (start date < end date). To reproduce, the two dates used as input have to be even number of months apart and the day of the start date has to be greater than the day of the end date (e.g. 2015-01-31 to 2015-03-01). Test script: --------------- <?php $date1 = new DateTime('2015/01/31'); $date2 = new DateTime('2015/03/01'); print_r($date1->diff($date2)); print_r($date2->diff($date1)); Expected result: ---------------- DateInterval Object ( [y] => 0 [m] => 1 [d] => 1 [h] => 0 [i] => 0 [s] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 0 [days] => 29 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 ) DateInterval Object ( [y] => 0 [m] => 1 [d] => 1 [h] => 0 [i] => 0 [s] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 29 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 ) Actual result: -------------- DateInterval Object ( [y] => 0 [m] => 0 [d] => 29 [h] => 0 [i] => 0 [s] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 0 [days] => 29 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 ) DateInterval Object ( [y] => 0 [m] => 1 [d] => 1 [h] => 0 [i] => 0 [s] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 29 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )