ID:               44073
 Updated by:       [EMAIL PROTECTED]
 Reported By:      freedman at freeformit dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Date/time related
 Operating System: FC6
 PHP Version:      5.2.5
 New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Many similar reports... and it's NOT a bug. From PHP 5.3 and higher you
can do:

"first day of +1 month" or "first day of next month" or even "last day
of next month" - those are always safe to use with just a "m" or another
month date format specifier.


Previous Comments:
------------------------------------------------------------------------

[2008-02-07 20:28:37] freedman at freeformit dot com

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
"[EMAIL PROTECTED] 
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



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44073&edit=1

Reply via email to