php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52340 strtotime conversion error
Submitted: 2010-07-15 01:50 UTC Modified: 2010-07-15 11:22 UTC
From: andrea dot romagnoli at getlocal dot it Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
 [2010-07-15 01:50 UTC] andrea dot romagnoli at getlocal dot it
Description:
------------
The result of subtraction between result of strtotime("Monday 29 March 2010 06:00:00") and the result of strtotime("Monday 22 March 2010 06:00:00") is not a week, but instead is a week less 2,5 minutes...

Infact a week are 604800 seconds but the result of this subtraction is 601200.

I tried to subtract day per day in the interval and all subtractions are correct and results every time 86400 seconds.

Test script:
---------------
<?php
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set ('Europe/London');

$dates = array("Monday 15 March 2010 06:00:00", "Monday 22 March 2010 06:00:00",
  "Monday 29 March 2010 06:00:00", "Monday 05 April 2010 06:00:00", "Monday 12 April 2010 06:00:00", "Monday 19 April 2010 06:00:00");

var_dump($dates);
$datesInt = array();
foreach($dates as $date)
  $datesInt[] = strtotime($date);

$lastDate = $datesInt[0];
for($i = 1; $i < count($datesInt); $i++){
  $tmp = $datesInt[$i]-$lastDate;
  var_dump($tmp);
  $lastDate = $datesInt[$i];
}
?>

Expected result:
----------------
I think that all subtractions should be return 604800 seconds.

Actual result:
--------------
Actually one of subtractions return 601200 instead of 604800 seconds.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-15 10:58 UTC] salathe@php.net
-Status: Open +Status: Bogus -Package: Calendar related +Package: Date/time related
 [2010-07-15 10:58 UTC] salathe@php.net
The actual number of seconds between those two date/times is expected. This is 
because it crosses a Daylight Savings boundary (at 2010-03-28T01:00:00+0000). 
Since the clocks went forward by an hour at that time, the number of seconds 
between the dates reflects that resulting in a "missing" hour.

For more information see http://en.wikipedia.org/wiki/Daylight_saving_time
 [2010-07-15 11:07 UTC] andrea dot romagnoli at getlocal dot it
Yes, but if I check the difference day by day from 22 march to 29 march is ever of 24H, why the daylight saving is show to me only if I subtract a week?
 [2010-07-15 11:21 UTC] salathe@php.net
The following will return 23 hours. If the result does not equate to your own 
"day by day" values please provide a similar short script to demonstrate the 
problem.

<?php
date_default_timezone_set('Europe/London');
$diff = strtotime('28 March 2010 06:00:00') - strtotime('27 March 2010 
06:00:00');
var_dump($diff / 3600); // difference in hours (23)
?>
 [2010-07-15 11:22 UTC] andrea dot romagnoli at getlocal dot it
Sorry, I made a big mistake...
Next time I will pay more attention before post a bug report.

Good work.
Best regards.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 16:01:36 2025 UTC