php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40917 strtotime() will not generate a timestamp close to 20061029 (BST)
Submitted: 2007-03-26 09:23 UTC Modified: 2007-03-26 09:41 UTC
From: team at iris dot ac Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.1 OS: GNU/Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: team at iris dot ac
New email:
PHP Version: OS:

 

 [2007-03-26 09:23 UTC] team at iris dot ac
Description:
------------
Whilst looping with strtotime(), manually incrementing the day by 1 on each iteration we are hitting an infinite loop where the date never goes beyond 20061029.  This has been happening since the shift to DST yesterday.

Take the following two demonstrations:

<?php

/** This works perfectly fine **/

$t = strtotime('20060901');
while ($t < strtotime('20070720'))
{
	$t += 86400;
	echo date("Ymd", $t) . "<br />";
}

?>

and...

<?php

/** This hangs at 20061029 **/

$t = date('Ymd', strtotime('20060901'));
while ($t < date('Ymd', strtotime('20070720')))
{
	$t = date('Ymd', strtotime($t)+86400);
	echo $t . "<br />";
}

?>

They should both logically do the same thing, and until we ran the code today they did do, but since the DST shift we see this hang at 20061029.

We've tested this on 5.1.6 and 5.2.1 with the same results.  It seems to work ok on 5.2.0.

We are in the Europe/London timezone (BST).

Reproduce code:
---------------
<?php

/** This works perfectly fine **/

$t = strtotime('20060901');
while ($t < strtotime('20070720'))
{
	$t += 86400;
	echo date("Ymd", $t) . "<br />";
}

?>

and...

<?php

/** This hangs at 20061029 **/

$t = date('Ymd', strtotime('20060901'));
while ($t < date('Ymd', strtotime('20070720')))
{
	$t = date('Ymd', strtotime($t)+86400);
	echo $t . "<br />";
}

?>

Expected result:
----------------
We expect the get a list of days between the start and end ranges, instead, we get a list of days up to 20061029, followed by a never ending list of 20061029 repeated whilst it tries to increment further, unsuccessfully.

Actual result:
--------------
20060902
20060903
20060904
20060905
20060906
20060907
20060908
20060909
20060910
20060911
20060912
20060913
20060914
20060915
20060916
20060917
20060918
20060919
20060920
20060921
20060922
20060923
20060924
20060925
20060926
20060927
20060928
20060929
20060930
20061001
20061002
20061003
20061004
20061005
20061006
20061007
20061008
20061009
20061010
20061011
20061012
20061013
20061014
20061015
20061016
20061017
20061018
20061019
20061020
20061021
20061022
20061023
20061024
20061025
20061026
20061027
20061028
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
20061029
.. and so on ....

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-26 09:41 UTC] derick@php.net
That is because 20061029 is not 24 hours (86400 seconds) but 25 hours (90000 seconds). The + 86400 seconds makes it only 20061029 23:00 hour (although GMT and no longer BST) and you remove the hour part, the day is back on 20061029 and thus you get the loop.

See this script on how to do this properly:
<?php

$t = date('Ymd', strtotime('20060901'));
while ($t < date('Ymd', strtotime('20070720')))
{
    $t = date('Ymd', strtotime("$t +1 day"));
    echo $t . "\n";
}

?>

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 17:00:02 2026 UTC