how to find this day is holiday in php day

Solutions on MaxInterview for how to find this day is holiday in php day by the best coders in the world

showing results for - "how to find this day is holiday in php day"
Gianluca
12 Jul 2017
1function observed_date($holiday){
2    $day = date("w", strtotime($holiday));
3    if($day == 6) {
4        $observed_date = $holiday -1;
5    } elseif ($day == 0) {
6        $observed_date = $holiday +1;
7    } else {
8        $observed_date = $holiday;
9    }
10    return $observed_date;
11}
12
13function get_holiday($holiday_name) {
14
15    $currentYear = date('Y');
16
17    switch ($holiday_name) {
18        // New Years Day
19        case "new_year":
20            $holiday = observed_date(date('Ymd', strtotime("first day of january $currentYear")));
21            break;
22        // Martin Luther King, Jr. Day
23        case "mlk_day":
24            $holiday = date('Ymd', strtotime("january $currentYear third monday"));
25            break;
26        // President's Day
27        case "presidents_day":
28            $holiday = date('Ymd', strtotime("february $currentYear third monday"));
29            break;
30        // Memorial Day
31        case "memorial_day":
32            $holiday = (new DateTime("Last monday of May"))->format("Ymd");
33            break;
34        // Independence Day
35        case "independence_day":
36            $holiday = observed_date(date('Ymd', strtotime("july 4 $currentYear")));
37            break;
38        // Labor Day
39        case "labor_day":
40            $holiday = date('Ymd', strtotime("september $currentYear first monday"));
41            break;
42        // Columbus Day
43        case "columbus_day":
44            $holiday = date('Ymd', strtotime("october $currentYear second monday"));
45            break;
46        // Veteran's Day
47        case "veterans_day":
48            $holiday = observed_date(date('Ymd', strtotime("november 11 $currentYear")));
49            break;
50        // Thanksgiving Day
51        case "thanksgiving_day":
52            $holiday = date('Ymd', strtotime("november $currentYear fourth thursday"));
53            break;
54        // Christmas Day
55        case "christmas_day":
56        $holiday = observed_date(date('Ymd', strtotime("december 25 $currentYear")));
57            break;
58
59        default:
60            $holiday = "";
61            break;
62    }
63    return $holiday;
64
65}
66
Sophie
14 Mar 2018
1    //function that checks if a holiday lands on saturday/sunday and so we can move them to a friday/monday respectively
2    private function getObservedDate($holidayDate){
3
4        $dayofweek = date("w", strtotime($holidayDate));
5
6        if ($dayofweek == 6) $holidayDate = date('m/d/Y', strtotime("$holidayDate - 1 days")); //saturday moves to friday
7        else if ($dayofweek == 0)  $holidayDate = date('m/d/Y', strtotime("$holidayDate + 1 days"));  //sunday moves monday
8
9        return $holidayDate;
10    }
11
12
13    //function that calculates the holidays for any given year
14    private function getFederalHolidaysForYear($year){
15
16        $NY = $this->getObservedDate( date('m/d/Y', strtotime("1/1/$year")) ); //new years day
17
18        $MLK = $this->getObservedDate( date('m/d/Y', strtotime("third monday of january $year")) );  //martin luther king day
19
20        $PD = $this->getObservedDate( date('m/d/Y', strtotime("third monday of february $year")) ); ; //presidents day
21
22        $MDay = $this->getObservedDate( date('m/d/Y', strtotime("last monday of May $year")) ); //memorial day  
23
24        $IDay = $this->getObservedDate( date('m/d/Y', strtotime("7/4/$year")) );  // independence day
25
26        $LD = $this->getObservedDate( date('m/d/Y', strtotime("first monday of september $year")) ); //labor day
27
28        $VD = $this->getObservedDate( date('m/d/Y', strtotime("11/11/$year")) ); //veterans day
29
30        $ColD =$this->getObservedDate( date('m/d/Y', strtotime("second monday of october $year")) ); //columbus day   
31
32        $TG = $this->getObservedDate( date('m/d/Y', strtotime("last thursday of november $year")) ); // thanksgiving       
33
34        $CD = $this->getObservedDate( date('m/d/Y', strtotime("12/25/$year")) );  //christmas day 
35
36        $nonWorkingDays = array();
37
38        array_push($nonWorkingDays, $NY, $MLK, $PD, $MDay, $IDay, $LD, $ColD, $VD, $TG, $CD);
39
40        return $nonWorkingDays;
41    }
42