php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43188 Daylight Savings Time Related Problem with Date()
Submitted: 2007-11-04 21:51 UTC Modified: 2007-12-08 15:52 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: ebrueggeman at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.4 OS: Windows
Private report: No CVE-ID: None
 [2007-11-04 21:51 UTC] ebrueggeman at gmail dot com
Description:
------------
The date() function is not accurately displaying output expected of dates during the 1 week long time before daylight savings time, likely because of the change in the start of daylight savings time from the year prior.

Reproduce code:
---------------
date_default_timezone_set ("America/New_York");
 
$receiptStamp=mktime(0, 0, 0, 10, 31, 2007);
$modStamp= $receiptStamp + (5 * 24 * 60 * 60);  /* Addition of 5 days of time */
echo date('m/d/Y', $modStamp) . '<br>';
/*
prints 11/04/2007
*/
 
$dateObject=new DateTime("10/31/2007");
$dateObject->modify("+5 day");
echo date_format( $dateObject, 'm/d/Y' ). '<br>';
 
/*
prints 11/05/2007
*/
 
 
/*After the old daylight savings crossover week*/
 
$dateObject=new DateTime("11/7/2007");
$dateObject->modify("+5 day");
echo date_format( $dateObject, 'm/d/Y' ). '<br>';
 
/*
prints 11/12/2007
*/
 
$receiptStamp=mktime(0, 0, 0, 11, 7, 2007);
$modStamp= $receiptStamp + (5 * 24 * 60 * 60);  /* Addition of 5 days of time */
echo date('m/d/Y', $modStamp). '<br>';

Expected result:
----------------
11/05/2007
11/05/2007
11/12/2007
11/12/2007

Actual result:
--------------
11/04/2007
11/05/2007
11/12/2007
11/12/2007

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-08 15:52 UTC] derick@php.net
This is correct behavior.

In the first example you add 5 times 24 hours, but in the 2nd one, you add 5 days. There is a subtle difference here because Sunday November 4th, 2007 actually has *25* hours.

You can see this in action if you add "H:i:s T" to your formatting strings:

<?php
date_default_timezone_set ("America/New_York");

$receiptStamp=mktime(0, 0, 0, 10, 31, 2007);
$modStamp= $receiptStamp + (5 * 24 * 60 * 60);  /* Addition of 5 days of time */
echo date('m/d/Y H:i:s T', $modStamp) . "\n";
/* prints 11/04/2007 */

$dateObject=new DateTime("10/31/2007");
$dateObject->modify("+5 day");
echo date_format( $dateObject, 'm/d/Y H:i:s T' ). "\n";

/* prints 11/05/2007 */

/*After the old daylight savings crossover week*/

$dateObject=new DateTime("11/7/2007");
$dateObject->modify("+5 day");
echo date_format( $dateObject, 'm/d/Y H:i:s T' ). "\n";

/* prints 11/12/2007 */

$receiptStamp=mktime(0, 0, 0, 11, 7, 2007);
$modStamp= $receiptStamp + (5 * 24 * 60 * 60);  /* Addition of 5 days of time */
echo date('m/d/Y H:i:s T', $modStamp). "\n";
?>

outputs:
11/05/2007 23:00:00 EST
11/05/2007 00:00:00 EST
11/12/2007 00:00:00 EST
11/12/2007 00:00:00 EST



 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 13 01:00:01 2025 UTC