note 114856 added to function.date-add
| From: | antony at harrisretail dot co dot uk | Date: | Tue, 15 Apr 2014 12:09:08 +0000 |
| Subject: | note 114856 added to function.date-add | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199272@lists.php.net to get a copy of this message | ||
When using DateTime::add() be careful that additions over Summertime changes will not always produce
the expected results. For instance, adding a day (interval = P1D) is probably expected to keep the
same time when added to a date even over a summertime change. But adding 24 hours (interval = PT24H)
does not seem to take into effect the time change.
When then checking the time difference after adding 24 hours after the clocks went forward, the time
difference is only 23 hours.
<?php
date_default_timezone_set('Europe/London');
$diff1Day = new DateInterval('P1D');
$diff24Hours = new DateInterval('PT24H');
$diff1440Minutes = new DateInterval('PT1440M');
// Clocks changed at 2014-03-30 02:00:00
$d0 = new DateTime('2014-03-29 08:00:00');
$d1 = new DateTime('2014-03-29 08:00:00');
// Add 1 day - expect time to remain at 08:00
$d1->add($diff1Day);
print_r($d1);
$d2 = new DateTime('2014-03-29 08:00:00');
// Add 24 hours - expect time to be 09:00
$d2->add($diff24Hours);
print_r($d2);
$seconds = $d1->getTimestamp() - $d0->getTimestamp();
echo "Difference in Hours: " . $seconds / (60 * 60) . "\n";
----
Server IP: 87.124.126.49
Probable Submitter: 109.231.201.34
----
Manual Page -- http://php.net/manual/en/function.date-add.php
Edit -- https://master.php.net/note/edit/114856
Del: integrated -- https://master.php.net/note/delete/114856/integrated
Del: useless -- https://master.php.net/note/delete/114856/useless
Del: bad code -- https://master.php.net/note/delete/114856/bad+code
Del: spam -- https://master.php.net/note/delete/114856/spam
Del: non-english -- https://master.php.net/note/delete/114856/non-english
Del: in docs -- https://master.php.net/note/delete/114856/in+docs
Del: other reasons-- https://master.php.net/note/delete/114856
Reject -- https://master.php.net/note/reject/114856
Search -- https://master.php.net/manage/user-notes.php