Check if DST is in effect

Nick Coons picture Nick Coons · Dec 6, 2013 · Viewed 8.2k times · Source

In PHP, date('I') will tell me if Daylight Savings Time is in effect. Does this tell me if DST is in effect specifically for my server's configured timezone, or whether or not it's in effect period?

I'm in Arizona where we don't observe DST. So I need my server to recognize that, say, New York is 2 hours ahead of me right now, but when DST kicks in March next year that it's 3 hours ahead of me.

Update:

Given the comment that it's for my server's configured time zone, how would I go about determining the current time difference between my server's time zone and some arbitrary timezone, knowing that the value changes throughout the year?

Answer

Tom McClure picture Tom McClure · Dec 6, 2013

PHP will honor your server's default time zone, so date('I') will always return false in Arizona if your server is correctly configured.

You may temporarily change the default time zone to an area that does observe DST. To change the default time zone use date_default_timezone_set() as indicated here.