Calculate DST
The following script calculates start and end of DST (daylight saving time) of a given year (as a timestamp):
<?php
function dst_start($year) {
return mktime(2,0,0,3,31-date('w', mktime(2,0,0,3,31,$year)),$year);
}
function dst_end($year) {
return mktime(2,0,0,10,31-date('w', mktime(2,0,0,10,31,$year)),$year);
}
?>
You can use date() to convert the timestamp into a human readable format:
<?php
/* usage-example 1 */
$year=2000;
$start_str=date('d.m.',dst_start($year));
$end_str=date('d.m.',dst_end($year));
echo "In $year, the daylight saving time began $start_str and ended $end_str<br />";
/* usage-example 2 */
echo "This year, the daylight saving time begins ".date('d.m.',dst_start(date('Y')));
/* usage-example 3 */
if(date('I')==0) {
// not DST at the moment
echo "The clock will be set to DST on ".date('d.m.',dst_start(date('Y')))."<br />";
} else {
// DST at the moment
echo "DST will end ".date('d.m.',dst_end(date('Y')))."<br />";
}
?>
Attention: This function uses the rules for DST defined by 2000/84/EG of the European parliament, which is used in Germany since 1996. For years before that and for other countries, you might need to adjust the function. If you have questions on how to adjust this for your country, feel free to contact me.
These functions are loosely based on excel formulas from excelformeln.de. Thanks.