php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60654 Strtotime taking leap year into effect before the leap
Submitted: 2012-01-04 13:51 UTC Modified: 2012-01-31 09:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: keloran at develbox dot info Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4SVN-2012-01-04 (SVN) OS: Gentoo
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: keloran at develbox dot info
New email:
PHP Version: OS:

 

 [2012-01-04 13:51 UTC] keloran at develbox dot info
Description:
------------
If you do the test, you should get if today is 
02/01/2012

the result should be
03/01/2011

but instead you get
02/01/2011

Test script:
---------------
echo date("d/m/Y", strtotime("yesterday last year"));

Expected result:
----------------
03/01/2011

Actual result:
--------------
02/01/2011

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-30 20:34 UTC] austin dot w dot best at gmail dot com
To add to this...

date('n', strtotime('+ 1 month', time()));

That should be 2 and it is returning a 3. Now it is 3:30 PM EST when i noticed 
this, so by using a preset timestamp you can reproduce this.

date('n', strtotime('+ 1 month', '1327954976'));

Will return 3 instead of 2 as well.

I am guessing this will never be fixed, and if not, maybe say "hey, we cant fix 
this one" -OR "this is more work to fix than it is worth" instead of ignoring 
the problem?

https://bugs.php.net/bug.php?id=27793 that is from 2004!!! 

Not to mention there is a note at the bottom of it that it was posted at least 5 
other times.
 [2012-01-30 23:00 UTC] rasmus@php.net
Keloran, your bug report is confusing with respect to day/month order. I am 
assuming you mean m/d when you say 02/01 and 03/01 but your script says d/m/Y.
Please provide an actual script with a timestamp baked in. Like this:

echo date("d/m/Y H:i:s\n",1328126500);
echo date("d/m/Y\n", strtotime("yesterday last year",1328126500));

That outputs:

01/02/2012 12:01:40
31/01/2011

which looks completely correct to me.

Austin, yours is not a bug. When you add a month to Jan.30 it goes to Feb.30 
which doesn't exist. So it adjusts it to Mar.1. strtotime follows the standard 
UNIX date addition behaviour in this. From your Linux command line try this:

% date
Mon Jan 30 17:49:22 EST 2012
% date --date='+1 month' +'Next month is %B'
Next month is March

You can find this behaviour documented here:
http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-
strings.html#SEC125
 [2012-01-30 23:00 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-01-31 09:20 UTC] keloran at develbox dot info
<?php
$preData = 1327928400;
$a = strtotime("last monday", $preDate);
$b = strtotime("last year last monday", $a);
$c = date("d/m/Y H:i:s", $a);
$d = date("d/m/Y H:i:s", $b);

print_r(array(
		"PreDate" => $preDate,
		"Today Time" => $a,
		"Last Year Time" => $b,
		"Converted Today" => $c,
		"Converted Last Year" => $d,
));
 [2012-01-31 09:21 UTC] keloran at develbox dot info
Array
(
    [PreDate] => 1327928400
    [Today Time] => 1327842000
    [Last Year Time] => 1295701200
    [Converted Today] => 30/01/2012 00:00:00
    [Converted Last Year] => 23/01/2011 00:00:00
)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 20:01:32 2025 UTC