php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14259 3rd Sunday of every March (has 25 hours?)
Submitted: 2001-11-27 17:15 UTC Modified: 2001-11-27 17:42 UTC
From: james at composite dot co dot nz Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.1.0 OS: Linux merlin 2.4.6
Private report: No CVE-ID: None
 [2001-11-27 17:15 UTC] james at composite dot co dot nz
While trying to get a list of dates between any two given dates by adding 86400 (secs per day) to each consecutive datetime, I discovered that adding 86400 (secs per day) to the 3rd Sunday of March (in any year) results in a datetime which is interpreted by the date() function as 23:00 hrs on the same Sunday - rather then 00:00 hr on the following day, as it should be.

There also seems to be a similar effect in reverse some time in October.

Have a look at the result of the following script, using any range of dates in $datetime_temp and $datetime_end.

<?php
	$datetime_temp = strtotime("2002-1-1");
	$datetime_end = strtotime("2002-12-31");

	echo "start: ".date("Y-n-j H:i:s", $datetime_temp);
	echo " end: ".date("Y-n-j H:i:s", $datetime_end)."<br/>\n";

	$datetimes = array();
	while($datetime_temp <= $datetime_end) {
		$datetimes[] = $datetime_temp;
		echo date("Y-n-j H:i:s", $datetime_temp)."<br/>\n";
		$datetime_temp += 86400;
	}
?>

Partial output:
...
2002-3-15 00:00:00
2002-3-16 00:00:00
2002-3-17 00:00:00
2002-3-17 23:00:00
2002-3-18 23:00:00
2002-3-19 23:00:00
...
2002-10-3 23:00:00
2002-10-4 23:00:00
2002-10-5 23:00:00
2002-10-7 00:00:00
2002-10-8 00:00:00
2002-10-9 00:00:00
...


What's happening?
Is there another/better way for me to get my list of dates?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-27 17:21 UTC] venaas@php.net
Daylight saving time I guess. I thought it should happen
between 2am and 3am, but that's maybe just where I am.
 [2001-11-27 17:38 UTC] derick@php.net
Daylight savings time.... use gmdate in this case.

Derick
 [2001-11-27 17:42 UTC] james at composite dot co dot nz
Ah! Boy do I feel stupid.

Thanks for the responses/help guys :-)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC