note 104361 deleted from dateinterval.format by danbrown
| From: | danbrown@php.net | Date: | Fri, 10 Jun 2011 15:27:03 +0000 |
| Subject: | note 104361 deleted from dateinterval.format by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180410@lists.php.net to get a copy of this message | ||
Note Submitter: petros at rufunka dot com
----
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.