Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fixes the daylight savings issue with EE
var $dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/New_york'));
$isDst = (bool)$dateTime->format('I') ? "y" : "n";
$conf['daylight_savings'] = $isDst;
Copy link

ghost commented Oct 29, 2012

Great workaround. (Note this is PHP 5.3+ only, but most hosts are using that now.)

Copy link

1stevengrant commented Oct 29, 2012

I can't take any credit for this - thanks go to @lowellkitchen for this

Copy link

kevinfodness commented Oct 29, 2012

If you have control over the server time, and/or the server time is set to what you want (e.g., server timezone set to the same timezone that you want for the website) you can do it in one line:

$config['daylight_savings'] = date('I') ? 'y' : 'n';

Copy link

amacneil commented Oct 31, 2012

@gregferrell Do you have a reference for this being 5.3 only? All I could find is the DateTime class being 5.2+

Copy link

lowellkitchen commented Oct 31, 2012

@adrianmacneil the setTimestamp method was added in PHP 5.3:

their are easy work arounds to this for folks not on PHP 5.3 yet.

Copy link

CleverLever commented Nov 4, 2012

Also set, this recently hosed me.

$config['default_site_dst'] = date('I') ? 'y' : 'n';

Copy link

CleverLever commented Nov 9, 2012

And you might have to do something like this for your old entries when going from UM6 (CDT) to UM5 (CST) and using "fixed" dates (field_id is 394).

update exp_channel_data SET field_dt_394 = 'UM5';

Or switch everything to localized using (field_id is 394).

update exp_channel_data SET field_dt_394 = '';

Copy link

rsanchez commented Jan 28, 2013

PHP 5.2 version:

$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/Chicago'));
$date = getdate();
$dateTime->setDate($date['year'], $date['mon'], $date['mday']);
$dateTime->setTime($date['hours'], $date['minutes'], $date['seconds']);
$conf['daylight_savings'] = $dateTime->format('I') ? 'y' : 'n';

Copy link

benjamin-smith commented Nov 6, 2013

America/New_york should be America/New_York, no?

Copy link

jayeshjain24 commented Apr 21, 2014

My website is having a countdown from 23july to current time.I am from india and my timing lag 5.30 hours.The problem is the site is also for pakistan,srilanka,bangladesh.So i need to have respective timezone using php.Any idea?Currently the countdown get deprecated by one day at 5.30 in morning instead of midnight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment