Re: Time Zone Calculations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 18/11/13 02:25, Ron Piggott wrote:
Hi Everyone

The result of the code below (Converting the time from GMT to Eastern , Then adding 561 Days and converting back to GMT) is giving me the result: 2013-11-18 14:32:00    I was expecting an hour earlier (2013-11-18 13:32:00)   Is there something I am doing wrong?

- I am trying to calculate 561 days in the future, but keeping the same time.

- The reason I thought about converting from GMT to Eastern and back to GMT was because I wondered if Daylight Savings Time was the issue.

Ron

<?php
$occurance_date = '2012-05-06 13:32:00';

$dt = new \DateTime( date('Y-m-d H:i:s' , strtotime( $occurance_date ) ) , new \DateTimeZone( 'GMT' ) );
$dt->setTimezone(new \DateTimeZone( "Canada/Eastern"  ));
$dt->modify('+561 days');
$dt->setTimezone(new \DateTimeZone( 'GMT'  ));
$revised_occurance_date = $dt->format('Y-m-d H:i:s');
?>

Ron Piggott



www.TheVerseOfTheDay.info


Hi Ron,

how exactly do add the number of days ? Do you use http://be.php.net/manual/en/datetime.add.php ?

Changing from GMT to Eastern is the wrong option: DST does not apply to GMT - it applies to the offset between GMT and local time. I.e. CEST is GMT+1 in winter, and GMT+2 in summer. In fact, best to do is change from local time to GMT, then shift days, and come back to local time.

Let me know if it works.

Bert

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux