php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12474 possible incorrect strtotime handling of "-1Month"
Submitted: 2001-07-30 20:53 UTC Modified: 2002-05-25 06:29 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: jbarrett at australink dot net Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.0.4pl1 OS: Linux (should happen on any)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 - 20 = ?
Subscribe to this entry?

 
 [2001-07-30 20:53 UTC] jbarrett at australink dot net
when running
<?PHP
print date("d/m/Y", strtotime("31 July 2001"))."\n";
print date("d/m/Y", strtotime("-1 month", strtotime("31 July 2001")))."\n";
?>

it replies with 
X-Powered-By: PHP/4.0.3pl1
Content-type: text/html

31/07/2001
01/07/2001

of course what it's doing is turning it into 31 june which is then being considered to be the 1 of july.. Should this be right or should strtotime realise that there are 30 days in june and truncate the "31st" day?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-20 03:48 UTC] lobbin@php.net
Confirmed with php 4.2.0-dev.

print date("d/m/Y", strtotime("1 month ago", strtotime("31 July 2001")))."\n";

Gives the same error, and that should be correct GNU date syntax?

R.
 [2002-05-25 06:29 UTC] derick@php.net
Not really a bug, it's exactly like GNU date behaves:

[derick@kossu derick]$ date --date='31 July 2001 -1 month'
Sun Jul  1 00:00:00 CEST 2001
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC