|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-04-07 06:08 UTC] requinix@php.net
-Type: Bug
+Type: Documentation Problem
[2020-04-07 08:55 UTC] derick@php.net
-Status: Open
+Status: Not a bug
[2020-04-07 08:55 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 10:00:02 2025 UTC |
Description: ------------ `modify` result is not intuitive when going back one month. If the current month has more days than the last one, modify ('-1 month') can end up in the same month. I believe, if that is the case, it should fall back to the last day of last month. The current way this works is completely unintuitive, and at least should be mentioned in the docs. Test script: --------------- $date = new DateTime (); $date->setDate (2020, 03, 30); // 31 days in march echo $date->format ("Y-m-d h:m:s") . PHP_EOL; $date->modify ("-1 month"); // only 28 days in february echo $date->format ("Y-m-d h:m:s") . PHP_EOL; Expected result: ---------------- 2020-03-30 07:03:18 2020-02-28 07:03:18 Actual result: -------------- 2020-03-30 07:03:18 2020-03-01 07:03:18