|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-02-11 08:32 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
Description: ------------ strtotime("+1 Month") produces the wrong result on the 31st day of the month. on January 31, date("m",strtotime("+1 Month")) will return 03 instead of 02 even if the documentation were to state that this is acceptable, it basically renders the function useless, since you'd have to always add a bunch of extra code to find out if it's the 31st so this really should be fixed. basically "+1 Month" is NOT the same as "+30 Days" I realize there's an issue when the 'day' of the month doesn't exist in the next month, however, this happens in half the months of the year, so basically, logically, I'd think the "last" day of this month "+1 month" would be the last day of the next month. in cases where next month has fewer days than this month. Using the example from http://bugs.php.net/bug.php?id=22486&edit=2 "rasmus@php.net If I told you on January 30 that I would come back in exactly one month to beat the crap out of you, when would you think I would show up?" However, if I told you on January 1 at 8am that I would come back in exactly one month to beat the crap out of you, according to his presumption that a month is "30.5" days, then would you expect me to show up on February 1 or January 31. The point is.. what "+1 Month" means, works differently on the 1st day of the month than it does on the last day of the month, and given the example of January 1 here, we can see that what it does on the 1st of a 31 day month and what it does on the last day preceeding a shorter month seem to apply different logic. Reproduce code: --------------- <? $t=strtotime("January 1, 2008"); echo date("c\n", strtotime("+1 Month",$t)); $t=strtotime("January 29, 2008"); echo date("c\n", strtotime("+1 Month",$t)); $t=strtotime("January 31, 2008"); echo date("c\n", strtotime("+1 Month",$t)); $t=strtotime("February 29, 2008"); echo date("c\n", strtotime("+1 Month",$t)); ?> produces: 2008-02-01T00:00:00-08:00 2008-02-29T00:00:00-08:00 2008-03-02T00:00:00-08:00 2008-03-29T00:00:00-07:00 Expected result: ---------------- expected result: 2008-02-01T00:00:00-08:00 2008-02-29T00:00:00-08:00 2008-02-29T00:00:00-08:00 2008-03-29T00:00:00-08:00 Actual result: -------------- 2008-02-01T00:00:00-08:00 2008-02-29T00:00:00-08:00 2008-03-02T00:00:00-08:00 2008-03-29T00:00:00-07:00