|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27793 strtotime behaving erraticly in month change
Submitted: 2004-03-31 03:34 UTC Modified: 2004-03-31 04:49 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: henrik at mindlocker dot no Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.5 OS: Mac OS X Server 10.3.3/Darwin7.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: henrik at mindlocker dot no
New email:
PHP Version: OS:


 [2004-03-31 03:34 UTC] henrik at mindlocker dot no
strtotime("- x month") will not work properly when 
around a month change. The following code example was 
run on 31.march. I have seen the previous bug reports 
that indicate that month is really an alias for 30.5 
days. However, this causes problems when you need to 
correctly iterate (dynamically) with the month keyword. 
It should iterate correctly when its specified as month, 
if not my opinion is that implementations should use 
strtotime("- ".$num*"30.5"." days");

Reproduce code:
for( $c=0;$c<12;$c++ )
 echo date("F",strtotime("-".$c." month"))."<br>";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-31 04:49 UTC]
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.

Already reported atleast *5* times.
 [2012-05-31 19:45 UTC] ian_dunn at yahoo dot com
Since this is reported as a bug so often, it might make sense to update the 
documentation to warn developers about this unexpected/unintuitive behavior. 
Regardless of whether you think it's a bug or not, it's clearly something that 
many developers stumble over, so it should be prominently documented.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 01:01:32 2024 UTC