note 86275 modified in function.date by thiago

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.