how to find this day is holiday in php day code example
Example 1: how to find this day is holiday in php day
private function getObservedDate($holidayDate){
$dayofweek = date("w", strtotime($holidayDate));
if ($dayofweek == 6) $holidayDate = date('m/d/Y', strtotime("$holidayDate - 1 days"));
else if ($dayofweek == 0) $holidayDate = date('m/d/Y', strtotime("$holidayDate + 1 days"));
return $holidayDate;
}
private function getFederalHolidaysForYear($year){
$NY = $this->getObservedDate( date('m/d/Y', strtotime("1/1/$year")) );
$MLK = $this->getObservedDate( date('m/d/Y', strtotime("third monday of january $year")) );
$PD = $this->getObservedDate( date('m/d/Y', strtotime("third monday of february $year")) ); ;
$MDay = $this->getObservedDate( date('m/d/Y', strtotime("last monday of May $year")) );
$IDay = $this->getObservedDate( date('m/d/Y', strtotime("7/4/$year")) );
$LD = $this->getObservedDate( date('m/d/Y', strtotime("first monday of september $year")) );
$VD = $this->getObservedDate( date('m/d/Y', strtotime("11/11/$year")) );
$ColD =$this->getObservedDate( date('m/d/Y', strtotime("second monday of october $year")) );
$TG = $this->getObservedDate( date('m/d/Y', strtotime("last thursday of november $year")) );
$CD = $this->getObservedDate( date('m/d/Y', strtotime("12/25/$year")) );
$nonWorkingDays = array();
array_push($nonWorkingDays, $NY, $MLK, $PD, $MDay, $IDay, $LD, $ColD, $VD, $TG, $CD);
return $nonWorkingDays;
}
Example 2: how to find this day is holiday in php day
function observed_date($holiday){
$day = date("w", strtotime($holiday));
if($day == 6) {
$observed_date = $holiday -1;
} elseif ($day == 0) {
$observed_date = $holiday +1;
} else {
$observed_date = $holiday;
}
return $observed_date;
}
function get_holiday($holiday_name) {
$currentYear = date('Y');
switch ($holiday_name) {
case "new_year":
$holiday = observed_date(date('Ymd', strtotime("first day of january $currentYear")));
break;
case "mlk_day":
$holiday = date('Ymd', strtotime("january $currentYear third monday"));
break;
case "presidents_day":
$holiday = date('Ymd', strtotime("february $currentYear third monday"));
break;
case "memorial_day":
$holiday = (new DateTime("Last monday of May"))->format("Ymd");
break;
case "independence_day":
$holiday = observed_date(date('Ymd', strtotime("july 4 $currentYear")));
break;
case "labor_day":
$holiday = date('Ymd', strtotime("september $currentYear first monday"));
break;
case "columbus_day":
$holiday = date('Ymd', strtotime("october $currentYear second monday"));
break;
case "veterans_day":
$holiday = observed_date(date('Ymd', strtotime("november 11 $currentYear")));
break;
case "thanksgiving_day":
$holiday = date('Ymd', strtotime("november $currentYear fourth thursday"));
break;
case "christmas_day":
$holiday = observed_date(date('Ymd', strtotime("december 25 $currentYear")));
break;
default:
$holiday = "";
break;
}
return $holiday;
}