Get a Quote Today!   |   + 1 (301) 424 3903




 
  Community
 
Need Help?
Visit our Training page
Request a Quote or Consultation
SIGN UP FOR THE TERATECH NEWSLETTER
 

ColdCuts

Cut: get Holiday UDF
Cut#: 324 
Cut Date: 11/12/2004 
Cutter: Kyle Dixon 
Topic: General 
Overview: Returns name of holiday for date input. i.e. #getHoliday('01-JAN-05')# returns 'New Years Day Observed'. This is also available in PL/SQL, email me for code.

 

Cut Code:
<cfscript>
   // Written by Kyle Dixon kyle969@hotmail.com
function getHoliday (inDate){
      IF (Not IsDate(inDate)){
         RETURN "Input parameter for isHoliday must be a valid date!";
      }
      IF(dayOfWeek(inDate) eq 1)                           // Sunday
         RETURN "Sunday";
      switch(Month(inDate)){
      CASE '1':
                                                      // New Years Day
         IF (ListFind('1,7', DayOfWeek(CreateDate(year(inDate),1,1))))
         {
            IF (ListFind('2,3', Day(inDate) ) AND DayofWeek(inDate) EQ 2)
               RETURN "New Years Day Observed";
         }
         ELSE
         {
            IF(day(inDate) EQ 1)
               RETURN "New Years Day";
         }
                                                      // M.L.K Day
         IF (Day(inDate) GT 14 AND Day(inDate) LT 22 AND DayOfWeek(inDate) EQ 2)
            RETURN "M.L.K Day";
      BREAK;
      
      CASE '2':
                                                      // Presidents Day
         IF (Day(inDate) GT 14 AND Day(inDate) LT 22 AND DayOfWeek(inDate) EQ 2)
            RETURN "Presidents Day";
      BREAK;
      
      CASE '5':
                                                      // Memorial Day
         IF (Day(inDate) GT 24 AND DayofWeek(inDate) EQ 2)
            RETURN "Memorial Day ";
      BREAK;
      
      CASE '7':
                                                      // Independence Day
         IF(ListFind('1,7', DayOfWeek(CreateDate(year(inDate),7,4))))
         {
            IF (ListFind('5,6', Day(inDate)) AND DayofWeek(inDate) EQ 2)
               RETURN "Independence Day Observed";
         }
         ELSE
         {      
            IF(day(inDate) EQ 4)
               RETURN "Independence Day";
         }
      BREAK;
      
      CASE '9':
                                                      // Labor Day
         IF(Day(inDate) LT 8 AND DayOfWeek(inDate) EQ 2)
            RETURN "Labor Day";
         BREAK;
      
      CASE '10':
                                                      // Columbus Day
         IF(Day(inDate) GT 7 AND Day(inDate) LT 15 AND DayOfWeek(inDate) EQ 2)
            RETURN "Columbus Day";
      BREAK;
      
      CASE '11':
                                                      /// Veterans Day
      
         IF(ListFind('1,7', DayOfWeek(CreateDate(year(inDate),11,11))))
         {
            IF (ListFind('12,13', Day(inDate)) AND DayofWeek(inDate) EQ 2)
               RETURN "Veterans Day Observed";
         }
         ELSE
         {
            IF(day(inDate) EQ 11)
               RETURN "Veterans Day";
         }
                                                      // Thanksgiving Day
         IF (Day(inDate) GT 21 AND Day(inDate) LT 29 AND DayOfWeek(inDate) EQ 5)
            RETURN "Thanksgiving Day";
      
      BREAK;
      
      CASE '12':
                                                      // Christmas Day
         IF (ListFind('1,7', DayOfWeek(CreateDate(year(inDate),12,25))))
         {
            IF (ListFind('26,27', Day(inDate)) AND DayofWeek(inDate) EQ 2)
               RETURN "Christmas Day Observed";
         }
         ELSE
         {
            IF(day(inDate) EQ 25)
               RETURN "Christmas Day";
         }
      BREAK;
   } // end case
      
      RETURN "";
   }
</cfscript>