php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: henrik at mindlocker dot no
New email:
PHP Version: OS:

 

 [2004-03-31 03:34 UTC] henrik at mindlocker dot no
Description:
------------
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:
----------------
March
February
Januar
December
November
October

Actual result:
--------------
March
January
December
December
October
October
...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-31 04:49 UTC] derick@php.net
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: Thu Apr 18 22:01:28 2024 UTC