Bug #55792 [Opn->Bgs]: strtotime("-1 month");
Edit report at https://bugs.php.net/bug.php?id=55792&edit=1
ID: 55792
Updated by: danielc@php.net
Reported by: fjm20016 at 163 dot com
Summary: strtotime("-1 month");
-Status: Open
+Status: Bogus
Type: Bug
Package: Date/time related
Operating System: windows
PHP Version: 5.3.8
-Assigned To:
+Assigned To: danielc
Block user comment: N
Private report: N
New Comment:
1) Use the add(), sub() or modify() DateTime methods for date math.
2) Adding months to dates on or after the 29th of the month is unreliable, as you've found.
When performing such operations, an advisable approach is changing the date to the first day of the
month, add or subtract the number of months desired, than change the date to the last day of that
month.
Previous Comments:
------------------------------------------------------------------------
[2011-09-27 02:13:46] fjm20016 at 163 dot com
Description:
------------
I often use strtotime, I won't change my program anywhere.
+1 month -1 month maybe as expected
Test script:
---------------
date("Y-m-d H:i:s", strtotime("-1 month", strtotime("2011-05-31
00:00:00")));
//2011-05-01 as expected
//2011-04-30 I Like
date("Y-m-d H:i:s", strtotime("+1 month", strtotime("2011-05-31
00:00:00")));
//2011-07-01 as expected
//2011-06-30 I Like
date("Y-m-d H:i:s", strtotime("-1 month", strtotime("2011-03-31
00:00:00")));
//2011-03-03 as expected
//2011-02-28 I Like
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55792&edit=1
Thread (2 messages)