note 104361 added to dateinterval.format
| From: | petros at rufunka dot com | Date: | Fri, 10 Jun 2011 15:23:16 +0000 |
| Subject: | note 104361 added to dateinterval.format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180409@lists.php.net to get a copy of this message | ||
I investigated the issue more and it is related to the timezone and more specifically between the
last day of February and the first day of March.
For example if I set my zone to Europe/Stockholm which is +1 GMT then if i set the $first = new
DateTime(â2011-03-01 00:59:00â²); I still get the wrong result. However an hour value above
or equal to +1 ie $first = new DateTime(â2011-03-01 00:59:00â²); will give the correct
example.
So if you are GMT + 2 you need to have a value above or equal to 2011-03-01 02:00:00.
A quick fix, to the link provided by balaclark is to set your timezone to UTC:
date_default_timezone_set(âUTCâ);
and in this case you match the time with the needed in order to get correct results.
Another example with the opposite results is to set your timezone to:
date_default_timezone_set(âAmerica/Mexico_Cityâ);
$first = new DateTime(â2011-02-28 22:01:00â²);
$second = new DateTime(â2011-03-29 03:00:00â²);
then the diff will think that you are in the same month. You need to insert a few hours earlier to
get correct results.
----
Server IP: 69.147.83.197
Probable Submitter: 82.99.7.10
----
Manual Page -- http://www.php.net/manual/en/dateinterval.format.php
Edit -- https://master.php.net/note/edit/104361
Del: integrated -- https://master.php.net/note/delete/104361/integrated
Del: useless -- https://master.php.net/note/delete/104361/useless
Del: bad code -- https://master.php.net/note/delete/104361/bad+code
Del: spam -- https://master.php.net/note/delete/104361/spam
Del: non-english -- https://master.php.net/note/delete/104361/non-english
Del: in docs -- https://master.php.net/note/delete/104361/in+docs
Del: other reasons-- https://master.php.net/note/delete/104361
Reject -- https://master.php.net/note/reject/104361
Search -- https://master.php.net/manage/user-notes.php