Quick Search:
 
 PHP Code: Define a schedule of holidays Jump to:  
Category: >> PHP Code >> Define a schedule of holidays  

<< lastnext >>

Snippet Name: Define a schedule of holidays

Description: Functions used to define a schedule of holidays. Can define non-fixed holidays
(eg. 3rd Sunday of June).

Also see:
» Convert UK Dates To mySQL Format Dates
» Delete files older than 'X'
» String to Date
» Month, Day, Year dropdown boxes
» Calculate date of Easter Sunday
» Calendar for any month any year
» Add and Subtract dates
» Basic PHP Calendar
» Convert Standard time to 24-hour time ...
» What Season Is It?
» Delete by date
» Days in month #2
» Days in month one
» Count days between dates
» Find days between dates one
» Build Date Select Boxes

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<? php
 
FUNCTION GetTimeStamp($MySqlDate) 
  { 
 
 
  $date_array = EXPLODE("-",$MySqlDate); // split the array 
 
  $var_year = $date_array[0]; 
  $var_month = $date_array[1]; 
  $var_day = $date_array[2]; 
 
  $var_timestamp = MKTIME(0,0,0,$var_month,$var_day,$var_year); 
  RETURN($var_timestamp); // return it to the user 
  }  // End function GetTimeStamp() 
 
FUNCTION ordinalDay($ord, $day, $month, $year) 
  // ordinalDay returns date of the $ord $day of $month. 
  // For example ordinalDay(3, 'Sun', 5, 2001) returns the 
  // date of the 3rd Sunday of May (ie. Mother's Day). 
  // 
  // Note: $day must be the 3 char abbr. for the day, as 
  //       given by date("D"); 
  // 
 
  { 
  $firstOfMonth = GetTimeStamp("$year-$month-01"); 
  $lastOfMonth  = $firstOfMonth + DATE("t", $firstOfMonth) * 86400; 
  $dayOccurs = 0; 
 
  FOR ($i = $firstOfMonth; $i < $lastOfMonth ; $i += 86400) 
     { 
     IF (DATE("D", $i) == $day) 
       { 
       $dayOccurs++; 
       IF ($dayOccurs == $ord) 
         { $ordDay = $i; } 
       } 
     } 
  RETURN $ordDay; 
  }  // End function ordinalDay() 
 
FUNCTION getNextHoliday() 
   // Looks through a lists of defined holidays and tells you which 
   // one is coming up next. 
   // 
   { 
   $year = DATE("Y"); 
 
   CLASS holiday 
     { 
     VAR $name; 
     VAR $date; 
     VAR $catNum; 
 
     FUNCTION holiday($name, $date, $catNum) 
        // Contructor to define the details of each holiday as it is created. 
        { 
        $this->name   = $name;   // Official name of holiday 
        $this->date   = $date;   // UNIX timestamp of date 
        $this->catNum = $catNum; // category, we used for databases access 
        } 
     } // end class holiday 
 
   $holidays[] = NEW holiday("Groundhog Day", GetTimeStamp("$year-2-2"), "20"); 
   $holidays[] = NEW holiday("Valentine's Day", GetTimeStamp("$year-2-14"), "14"); 
   $holidays[] = NEW holiday("St. Patrick's Day", GetTimeStamp("$year-3-17"), "15"); 
   $holidays[] = NEW holiday("Easter", EASTER_DATE($year), "16"); 
   $holidays[] = NEW holiday("Mother's Day", ordinalDay(2, 'Sun', 5, $year), "3"); 
   $holidays[] = NEW holiday("Father's Day", ordinalDay(3, 'Sun', 6, $year), "4"); 
   $holidays[] = NEW holiday("Independence Day", GetTimeStamp("$year-7-4"), "17"); 
   $holidays[] = NEW holiday("Christmas", GetTimeStamp("$year-12-25"), "13"); 
 
   $numHolidays = COUNT($holidays); 
   FOR ($i = 0; $i < $numHolidays; $i++) 
     { 
     IF ( DATE("z") > DATE("z", $holidays[$i]->date) && DATE("z") <= DATE("z", 
          $holidays[$i+1]->date) ) 
        { 
        $nextHoliday["name"]      = $holidays[$i+1]->name; 
        $nextHoliday["dateStamp"] = $holidays[$i+1]->date; 
        $nextHoliday["dateText"]  = DATE("F j, Y", $nextHoliday["dateStamp"]); 
        $nextHoliday["num"]       = $holidays[$i+1]->catNum;         
        } 
     } 
   RETURN $nextHoliday; 
   } // end function GetNextHoliday 
 
 
$nextHoliday = getNextHoliday(); 
ECHO $nextHoliday["name"]." (".$nextHoliday["dateText"].")"; 
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org