php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55792 strtotime("-1 month");
Submitted: 2011-09-27 02:13 UTC Modified: 2011-11-21 17:15 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: fjm20016 at 163 dot com Assigned: danielc (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.3.8 OS: windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fjm20016 at 163 dot com
New email:
PHP Version: OS:

 

 [2011-09-27 02:13 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-27 10:06 UTC] cataphract@php.net
-Package: *Data Exchange functions +Package: Date/time related
 [2011-11-21 17:15 UTC] danielc@php.net
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.
 [2011-11-21 17:15 UTC] danielc@php.net
-Status: Open +Status: Bogus -Assigned To: +Assigned To: danielc
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC