I would like to know whether a date is in daylight saving time.
So I do this:
echo date('I', strtotime('2017-03-23')); // outputs 0
echo date('I', strtotime('2017-03-29')); // outputs 0
I expect to have different results for the two inputs, as the switch in the UK is 26 March 2017, however the output is 0 in both cases.
I have checked and the time zone looks correct:
echo date_default_timezone_get(); // outputs UTC
As you can see in this answer, UTC
does not have daylight saving, you need to set your timezone to Europe/London
:
date_default_timezone_set('Europe/London');
echo date('I', strtotime('2017-03-23')); // echoes 0
echo date('I', strtotime('2017-03-29')); // echoes 1
date_default_timezone_set('UTC');
echo date('I', strtotime('2017-03-23')); // echoes 0
echo date('I', strtotime('2017-03-29')); // echoes 0