php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36861 strtotime off by .04 seconds
Submitted: 2006-03-26 04:23 UTC Modified: 2006-03-26 05:35 UTC
From: rikkext1 at drdanger dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.1.2 OS: xp / linux
Private report: No CVE-ID: None
 [2006-03-26 04:23 UTC] rikkext1 at drdanger dot com
Description:
------------
I tripped across this bug calculating the number of days between two dates. It seems like something goes screwy in April and 0.041666667 seconds get dropped. The code below checks the difference in days between May 31 and the first 10 days of April. 

Reproduce code:
---------------
for ($iyear=2000;$iyear<= 2006;$iyear++) {
	$s_st=$iyear."-03-31";
	$st=strtotime($s_st);
	for ($i=1;$i<=10;$i++) {
		$addsecs=$st + ($i * 60 * 60 * 24);
		$end = st + $addsecs;
		$s_end=Date("Y-m-d",$end);
		$end = strtotime($s_end);
		$idiff = ($end - $st) / (60 * 60 * 24);
		echo("Start: $s_st End: $s_end Diff: $idiff<br>");
	}
	echo("<hr>");
}


Expected result:
----------------
I would expect to see the number of days between the dates in question 

Actual result:
--------------
Here's the results for just for 2006

Start: 2006-03-31 End: 2006-04-01 Diff: 1
Start: 2006-03-31 End: 2006-04-02 Diff: 2
Start: 2006-03-31 End: 2006-04-03 Diff: 2.9583333333333
Start: 2006-03-31 End: 2006-04-04 Diff: 3.9583333333333
Start: 2006-03-31 End: 2006-04-05 Diff: 4.9583333333333
Start: 2006-03-31 End: 2006-04-06 Diff: 5.9583333333333
Start: 2006-03-31 End: 2006-04-07 Diff: 6.9583333333333
Start: 2006-03-31 End: 2006-04-08 Diff: 7.9583333333333
Start: 2006-03-31 End: 2006-04-09 Diff: 8.9583333333333
Start: 2006-03-31 End: 2006-04-10 Diff: 9.9583333333333


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-26 04:28 UTC] rikkext1 at drdanger dot com
(Sorry, meant to say "difference between MARCH 31 and the first 10 days of April")
 [2006-03-26 05:33 UTC] rikkext1 at drdanger dot com
Just noticed, the seconds get dropped at the beginning of DST.
 [2006-03-26 05:35 UTC] rikkext1 at drdanger dot com
See last comment. I'm an idiot. Sorry.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 11:01:33 2024 UTC