Since the time has just changed the past weekend in places that use Daylight Savings Time I’m sure there’s going to be a few queries related to this.
I am trying to determine if a date used DST or not. For this I assume the 30th of October 2011 does not use DST, as the switch occurred on that date..is this correct?
Here is the code (I would expect Oct 30th to not use DST ):
<?php
echo "Timezone = " . date_default_timezone_get();
echo "</br>";
$dateOct29='2011-10-29';
$dateOct29Timestamp=strtotime($dateOct29,time());
$checkDayLightSavingOct29=date('I',$dateOct29Timestamp);
echo "Date : ".$dateOct29." Timestamp : ".$dateOct29Timestamp." Formatted ('Y-m-d Z T'): ".date('Y-m-d Z T',$dateOct29Timestamp)."</br>";
echo "Result of date('I',timestamp) : ". $checkDayLightSavingOct29."</br>";
$dateOct30='2011-10-30';
$dateOct30Timestamp=strtotime($dateOct30,time());
$checkDayLightSavingOct30=date('I',$dateOct30Timestamp);
echo "Date : ".$dateOct30." Timestamp : ".$dateOct30Timestamp." Formatted ('Y-m-d Z T'): ".date('Y-m-d Z T',$dateOct30Timestamp)."</br>";
echo "Result of date('I',timestamp) : ". $checkDayLightSavingOct30."</br>";
$dateOct31='2011-10-31';
$dateOct31Timestamp=strtotime($dateOct31,time());
$checkDayLightSavingOct31=date('I',$dateOct31Timestamp);
echo "Date : ".$dateOct31." Timestamp : ".$dateOct31Timestamp." Formatted ('Y-m-d Z T'): ".date('Y-m-d Z T',$dateOct31Timestamp)."</br>";
echo "Result of date('I',timestamp) : ". $checkDayLightSavingOct31."</br>";
$dateNov01='2011-11-01';
$dateNov01Timestamp=strtotime($dateNov01,time());
$checkDayLightSavingNov01=date('I',$dateNov01Timestamp);
echo "Date : ".$dateNov01." Timestamp : ".$dateNov01Timestamp." Formatted ('Y-m-d Z T'): ".date('Y-m-d Z T',$dateNov01Timestamp)."</br>";
echo "Result of date('I',timestamp) : ". $checkDayLightSavingNov01."</br>";
?>
This prints the following:
Timezone = Europe/Dublin
Date : 2011-10-29 Timestamp : 1319842800 Formatted (‘Y-m-d Z T’): 2011-10-29 3600 IST
Result of date(‘I’,timestamp) : 1
Date : 2011-10-30 Timestamp : 1319929200 Formatted (‘Y-m-d Z T’): 2011-10-30 3600 IST
Result of date(‘I’,timestamp) : 1
Date : 2011-10-31 Timestamp : 1320019200 Formatted (‘Y-m-d Z T’): 2011-10-31 0 GMT
Result of date(‘I’,timestamp) : 0
Date : 2011-11-01 Timestamp : 1320105600 Formatted (‘Y-m-d Z T’): 2011-11-01 0 GMT
Result of date(‘I’,timestamp) : 0
October 30th uses DST up to about 3 AM. Since your times are at midnight, this is before the DST change and therefore the 30th is being marked as having DST. Try setting the time to 10AM, and that should give correct results.