I remember somewhere, someone had posted a question on handling holidays. i cant seem to find the thread, but this might be of assistance to others in need of finding whether or not a given date is a holiday :
args are a given date value i.e. 07/04/04
returns holiday name or true/false based on internal variable (see below)
DreX
aKa - Robert
args are a given date value i.e. 07/04/04
returns holiday name or true/false based on internal variable (see below)
Code:
Function IsHoliday(datevalue)
returnholidayname=False '[green] false returns true/false value
' True returns holiday name[/green]
If not IsDate(datevalue) then
IsHoliday = -1
exit function
Else
Datevalue = cdate(datevalue)
End If
YearVal = year(datevalue)
holidays = Array("01/01/" & YearVal, "New Years", FindDate(1, "1/14/" & YearVal, False), "Martin Luther King Day", FindDate(1, "6/1/" & YearVal, True), "Labor Day", "07/04/" & YearVal, "Independance Day", FindDate(1, "9/7/" & YearVal, True), "Memorial Day", FindDate(4, "11/30/" & YearVal, True), "Thanksgiving", "12/25" & YearVal, "Christmas", "01/01/" & YearVal+1, "New Years")
'[green] the year + 1 is only for looking for possibilities of next years date, just incase the script is run right at the break of midnight, the new years for the current year of search is handled at the beginning of the array[/green]
If returnholidayname Then
IsHoliday = ""
Else
IsHoliday = False
End If
For Holiday = 0 To UBound(holidays) Step 2
holidays(Holiday) = CDate(holidays(Holiday))
If holidays(Holiday) = datevalue Then
If returnholidayname Then
IsHoliday = holidays(Holiday + 1)
Else
IsHoliday = True
End If
Exit For
End If
Next
End Function
'[green] following function is paired off with the prior function and finds a given day of the week based off a starting point
' arguments are dayval ( int 1-7 starting with monday ending with sunday )
' startdate datevalue for which to start searching
' findbackward true/false for direction of search true to cycle backwards in time, false to progress forward[/green]
Function FindDate(DayVal,StartDate,FindBackward)
If Not IsDate(StartDate) Then Exit Function
StartDate = CDate(StartDate)
If Not IsNumeric(DayVal) Then Exit Function
DayVal = CInt(DayVal)
On Error Resume Next
If FindBackward Then
For i = 1 To 8
If WeekDay(StartDate - i, vbMonday) = DayVal Then
FindDate = StartDate - i
Exit Function
End If
Next
Else
For i = 0 To 6
If WeekDay(StartDate + i, vbMonday) = DayVal Then
FindDate = StartDate + i
Exit Function
End If
Next
End If
FindDate = "Error"
End Function
![[thumbsup2] [thumbsup2] [thumbsup2]](/data/assets/smilies/thumbsup2.gif)
aKa - Robert