8

The PHP date("I") returns either a 0 or 1 depending on if the current date is in daylight savings. However, i need this exact function to return a 0 or 1 for a specified date and time in the future or past.

Any ideas how this can be achieved?

j0k
  • 22,600
  • 28
  • 79
  • 90
Ahmed
  • 1,403
  • 4
  • 21
  • 44
  • 1
    of course, there is an hour in October when the given time occurs both in standard time and daylight saving, so there is potential ambiguity here. It's a fairly small potential, but it is there. – Spudley Jan 20 '13 at 10:37

1 Answers1

15

Just pass the timestamp of the future date like this:

is_daylight_saving = date("I", future_timestamp);

See PHP date() documentation

****** EDIT:******

To properly get the daylight saving information you need to make sure that your default locale is set to a country using daylight saving. The list of countries using daylight savings can be found here.

To change the default time zone use date_default_timezone() as follows:

date_default_timezone_set('Europe/Rome'); // Italy uses daylight saving
echo date("I", 1366456706); // will return 1

date_default_timezone_set('America/Argentina/Buenos_Aires'); // Argentina doesn't use daylight saving
echo date("I", 1366456706);  // will return 0
mainer207
  • 3
  • 4
Tomas Camin
  • 9,996
  • 2
  • 43
  • 62
  • 1
    Thanks for your reply Tomas, but i tried that and it does not work. I got a timestamp of 1366456706 which translates to 20 April 2013 and falls within the daylight savings time. When i get this timestamp converted via a timestamp converter it says GMT +1 which indicates that it is in daylight savings but the date("I") is still returning zero. i tried this: date("I", "1366456706"); but not luck – Ahmed Jan 20 '13 at 11:21
  • future_timestamp is an integer, not a string. Try date("I", 1366456706); – Tomas Camin Jan 20 '13 at 11:32
  • thanks Tomas, but still returning 0. if i copy and paste that time stamp on a website that converts timestamps to date and time it says GMT+1. is there maybe any other way to quickly determine weather a timestamp has this GMT+1 status? Thanks – Ahmed Jan 20 '13 at 14:29
  • Perfect. Works perfectly now. Thanks Tomas. – Ahmed Jan 20 '13 at 17:28