#40917 [Opn->Bgs]: strtotime() will not generate a timestamp close to 20061029 (BST)

From: Date: Mon, 26 Mar 2007 09:41:52 +0000
Subject: #40917 [Opn->Bgs]: strtotime() will not generate a timestamp close to 20061029 (BST)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110778@lists.php.net to get a copy of this message
ID: 40917 Updated by: derick@php.net Reported By: team at iris dot ac -Status: Open +Status: Bogus Bug Type: Date/time related Operating System: GNU/Linux PHP Version: 5.2.1 New Comment: 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"; } ?> Previous Comments: ------------------------------------------------------------------------ [2007-03-26 09:23:40] 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 .... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40917&edit=1

« previous php.bugs (#110778) next »