note 86275 modified in function.date by thiago

From: Date: Fri, 10 Oct 2008 13:39:58 +0000
Subject: note 86275 modified in function.date by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145243@lists.php.net to get a copy of this message
Hi ! I've had a specific need to find out if a day is the day when a country switch to winter/spring times , aka loosing one hour or getting one hour compared to the real time .. This works in europe , but i don't know about other regulations or countries , so be warned. The switch to "spring time" is always on the last saturday of march. The switch to winter time is always last saturday of october. Hope it helps ! use it like this : <?php if(checkSwitchToWinterTime('20081025'){ echo 'today we switch to winter time' ; } function checkSwitchToWinterTime($day){ //day is yyyymmdd $y =substr($day,0,4); $m = substr($day,4,2); $d = substr($day,6,2); // if it is a saturday of october, check if it's the last one if(date("D-m", mktime(0, 0, 0, $m, $d, $y))=="Sat-10"){ ; if((date("m", mktime(0, 0, 0, $m, $d, $y))) != (date("m", mktime(0, 0, 0, $m, $d+7, $y)))) { return true; } return; } return; } function checkSwitchToSpringTime($day){ //day is yyyymmdd $y =substr($day,0,4); $m = substr($day,4,2); $d = substr($day,6,2); // if it is a saturday of march, check if it's the last one if(date("D-m", mktime(0, 0, 0, $m, $d, $y))=="Sat-03"){ ; if((date("m", mktime(0, 0, 0, $m, $d, $y))) != (date("m", mktime(0, 0, 0, $m, $d+7, $y)))) { return true; } return; } return; } ?> --was-- Hi ! I've had a specific need to find out if a day is the day when a country switch to winter/spring times , aka loosing one hour or getting one hour compared to the real time .. This works in europe , but i don't know about other regulations or countries , so be warned. The switch to "spring time" is always on the last saturday of march. The switch to winter time is always last saturday of october. Hope it helps ! use it like this : if(checkSwitchToWinterTime('20081025'){ echo 'today we switch to winter time' ; } function checkSwitchToWinterTime($day){ //day is yyyymmdd $y =substr($day,0,4); $m = substr($day,4,2); $d = substr($day,6,2); // if it is a saturday of october, check if it's the last one if(date("D-m", mktime(0, 0, 0, $m, $d, $y))=="Sat-10"){ ; if((date("m", mktime(0, 0, 0, $m, $d, $y))) != (date("m", mktime(0, 0, 0, $m, $d+7, $y)))) { return true; } return; } return; } function checkSwitchToSpringTime($day){ //day is yyyymmdd $y =substr($day,0,4); $m = substr($day,4,2); $d = substr($day,6,2); // if it is a saturday of march, check if it's the last one if(date("D-m", mktime(0, 0, 0, $m, $d, $y))=="Sat-03"){ ; if((date("m", mktime(0, 0, 0, $m, $d, $y))) != (date("m", mktime(0, 0, 0, $m, $d+7, $y)))) { return true; } return; } return; } http://php.net/manual/en/function.date.php

« previous php.notes (#145243) next »