|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 23:00:01 2025 UTC |
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