2

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
Miklos
  • 253
  • 3
  • 13

1 Answers1

3

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
Community
  • 1
  • 1
roberto06
  • 3,844
  • 1
  • 18
  • 29