note 104361 added to dateinterval.format

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

« previous php.notes (#180409) next »