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
 [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-2022 The PHP Group
All rights reserved.
Last updated: Fri May 20 16:03:34 2022 UTC