From:             freedman at freeformit dot com
Operating system: FC6
PHP version:      5.2.5
PHP Bug Type:     Date/time related
Bug description:  strtotime "+1 Month" fails on 31st day of month

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 bug report at http://bugs.php.net/?id=44073&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=44073&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44073&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44073&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44073&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44073&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44073&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44073&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44073&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44073&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44073&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44073&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44073&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44073&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44073&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=44073&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=44073&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44073&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44073&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44073&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44073&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44073&r=mysqlcfg

Reply via email to