note 104361 deleted from dateinterval.format by danbrown

From: 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.

« previous php.notes (#180410) next »