Holiday dates

from the Artful MySQL Tips List


Most of the job of finding holiday dates can be automated, the basics with a calendar table, see that topic at https://artfulsoftware.com/infotree/mysqltips.php, and holidays dates with simple logic like that implemented with these little php funcs for US holidays ...

<?php
function market_holiday_dates$yrs ) {
  
$yr date('Y');  // THIS YEAR
  
$a = array();
  
$a[] = array("Year","New Years","MLK Day","President","Good Friday","Memorial",
               
"4 July","Labor Day","Thanksgiving","Christmas"
              
);
  
$ymd "Y-m-d";
  for( 
$y=$yr$y<$yr+$yrs$y++ ) {
    
$a[] = array(
            
$y,
            
wknd_adjdate("$y-01-01") ),
            
date$ymdstrtotime("third monday of january $y") ), 
            
date$ymdstrtotime("third monday of February $y") ),
            
add_daysdate($ymd,easter_date($y)), -),
            
date$ymdstrtotime("last monday of may $y") ),
            
date$ymdstrtotime("$y-07-04") ),
            
date$ymdstrtotime("first monday of september $y") ),
            
date$ymdstrtotime("fourth thursday of november $y") ),
            
wknd_adjdate("$y-12-25") )            
           );
  }
  return 
$a;
}

function 
add_days$date$days ) {
  
$timeStamp strtotime$date ); 
  
$timeStamp+= 24 60 60 $days;
  return 
date"Y-m-d"mktime000date("n",$timeStamp),date("j",$timeStamp), date("Y",$timeStamp) ) ); 
}

function 
wknd_adj$d ) {
  if( 
date('N',strtotime($d))==) return add_days$d, -);
  elseif( 
date('N',strtotime($d))==) return add_days$d);
  else return 
$d;
}
?>


Adjust as desired for another country's holidays.

Last updated 20 Dec 2024


Return to the Artful MySQL Tips page