#30532 [Com]: strtotime - crossing daylight savings time

From: Date: Mon, 01 Nov 2004 02:20:22 +0000
Subject: #30532 [Com]: strtotime - crossing daylight savings time
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-68549@lists.php.net to get a copy of this message
ID: 30532 Comment by: gcon820 at yahooihatespam dot com Reported By: rbro at hotmail dot com Status: Open Bug Type: Date/time related Operating System: Linux PHP Version: 4.3.9 New Comment: I have experienced this problem with regards to daylight savings time as well. I print a calendar dynamically using strtotime, and on October 31, 2004 (the day of daylight savings), it printed October, December, December, January, March, March, May, May, July, July, August, October, instead of the months of October 2004-October 2005 consecutively. I printed out the value of print_r(getdate(strtotime("+$offset month", $start_date))), with $start_date being getdate(mktime())[0], and $offset being a number between 0 and 11. For each case, the [0] value printed out was different and correct. All other information in the getdate() array was incorrect, however. Hope this helps. gcon Previous Comments: ------------------------------------------------------------------------ [2004-10-31 02:15:12] jack dot littleton at gmail dot com I've recently experienced this same problem in the following way: On Friday, October 29, 2004 I sent strtotime the value ('Monday'), should have returned the data for Monday, November 1, 2004, but instead returned Sunday, October 31, 2004. I have never had a similar problem with strtotime when the span of the current time to the target time did NOT cross the daylight savings time boundary. (Further: this was on Windows XP SP1 using Apache 2 and PHP 4.3.5) ------------------------------------------------------------------------ [2004-10-22 22:32:27] rbro at hotmail dot com Further information: The following script does give the expected results: <?php echo date('Y-m-d H:i:s', strtotime('+1 hour', strtotime('2004-10-31')))."\n"; echo date('Y-m-d H:i:s', strtotime('+2 hours', strtotime('2004-10-31')))."\n"; echo date('Y-m-d H:i:s', strtotime('+3 hours', strtotime('2004-10-31')))."\n"; ?> of 2004-10-31 01:00:00 2004-10-31 01:00:00 2004-10-31 02:00:00 So now I believe the issue is that the following 2 statements give different output though they should have the same output: <?php echo strtotime('2004-10-31 +2 hours')."\n"; echo strtotime('+2 hours', strtotime('2004-10-31'))."\n"; ?> ------------------------------------------------------------------------ [2004-10-22 17:33:21] rbro at hotmail dot com Description: ------------ In the US, Daylight Savings Time ends on October 31, 2004 at 2am where clocks are then reset back to 1am. I am in the Eastern time zone. If I run the following script where I'm adding 1 hour, 2 hours, and 3 hours to the date 2004-10-31, I'm getting different results from including EDT in the date or not, when I thought that strtotime() defaults to the local timezone. Reproduce code: --------------- <?php echo date('Y-m-d H:i:s', strtotime('2004-10-31 EDT +1 hour'))."\n"; echo date('Y-m-d H:i:s', strtotime('2004-10-31 EDT +2 hours'))."\n"; echo date('Y-m-d H:i:s', strtotime('2004-10-31 EDT +3 hours'))."\n"; echo "\n"; echo date('Y-m-d H:i:s', strtotime('2004-10-31 +1 hour'))."\n"; echo date('Y-m-d H:i:s', strtotime('2004-10-31 +2 hours'))."\n"; echo date('Y-m-d H:i:s', strtotime('2004-10-31 +3 hours'))."\n"; ?> Expected result: ---------------- 2004-10-31 01:00:00 2004-10-31 01:00:00 2004-10-31 02:00:00 2004-10-31 01:00:00 2004-10-31 01:00:00 2004-10-31 02:00:00 Actual result: -------------- 2004-10-31 01:00:00 2004-10-31 01:00:00 2004-10-31 02:00:00 2004-10-31 01:00:00 2004-10-31 02:00:00 2004-10-31 03:00:00 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30532&edit=1

« previous php.bugs (#68549) next »