php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46211 strtotime give wrong result when DST changes
Submitted: 2008-10-01 15:19 UTC Modified: 2008-10-03 15:46 UTC
From: cmt042 at motorola dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.6 OS: UNIX
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cmt042 at motorola dot com
New email:
PHP Version: OS:

 

 [2008-10-01 15:19 UTC] cmt042 at motorola dot com
Description:
------------
When DST changes, the strtotime function give back wrong result.

Reproduce code:
---------------
// Need to adjust the day or hour numbers when run the code to make it cross the DST, Mar 8th 2:00AM 2009

$output = array();
  
for ($i = 15; $i <=19; $i++)
{
  $t = strtotime("+157 days +${i} hours");
  $output[] = date("r",$t);
}

foreach ($output as $line)
    print $line . "\n";


Expected result:
----------------
  
Sun, 08 Mar 2009 00:54:09 -0600
Sun, 08 Mar 2009 01:54:09 -0600
Sun, 08 Mar 2009 03:54:09 -0500
Sun, 08 Mar 2009 04:54:09 -0500
Sun, 08 Mar 2009 05:54:09 -0500

Actual result:
--------------
  
Sun, 08 Mar 2009 00:54:09 -0600
Sun, 08 Mar 2009 01:54:09 -0600
Sun, 08 Mar 2009 03:54:09 -0500
Sun, 08 Mar 2009 03:54:09 -0500
Sun, 08 Mar 2009 04:54:09 -0500

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-01 23:56 UTC] jani@php.net
We are happy to tell you that you just discovered Daylight Savings
Time. For more information see:
http://webexhibits.org/daylightsaving/b.html
Instead of using mktime/date consider using gmmktime and gmdate which do
not suffer from DST.


 [2008-10-03 15:46 UTC] cmt042 at motorola dot com
Can you have a close look at the actual and expected result?

The DST change does make the 3rd role in the Actual result right. But it's the 4th role and 5 role which is not right, as I mentioned in the expected result. 

Time should not freeze for one hour after changed in DST. The DST website did not mention this rule at all. 

Here is the printout of the return of strtotime function.

1236493432
1236497032
1236500632
1236500632  //one hour lost. expected is 1236500632+ 3600
1236504232  //same here

The absolute time value should not be affected by DST.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 22 21:00:03 2025 UTC