figuring holidays programatically

1. Senior Member
Join Date
Dec 1969
Posts
115

## figuring holidays programatically

Hi I need to figure out when labor day and memorial day will fall on each year, anyone have any idea what is the best way of doing this? i tried this but I think it will only work for one year (this year)<BR><BR>Function LastDayOfMonth(sMonth, sYear)<BR>dim tmpMonth, tmpYear<BR>tmpMonth = sMonth<BR>tmpYear = sYear<BR><BR>LastDayOfMonth = dateadd("d", -1, Dateadd("m", 1, tmpMonth & "/1/" & tmpYear))<BR>End Function<BR>Function IsHoliday(sDate)<BR>Dim iDay, iTmpDay, i<BR><BR>IsHoliday = 0<BR>iDay = Day(sDate)<BR><BR> For i = 1 To 31 &#039;Memorial Day<BR> If Weekday(DateAdd("d", "-" & i,CDate("5/31/" & Year(sDate)))) = 2 Then<BR> If CDate(sDate) = CDate(DateAdd("d", "-" & i,CDate("5/31/" & Year(sDate)))) Then<BR> IsHoliday = memorial<BR> End If<BR> Exit For<BR> End If<BR> next<BR>For i = 1 To 13 &#039;Labor Day<BR> If Weekday(DateAdd("d", i, CDate("9/1/" & Year(sDate)))) = 2 Then<BR> If CDate(sDate) = CDate(DateAdd("d", i, CDate("9/1/" & Year(sDate)))) Then<BR> IsHoliday = laborday<BR> End If<BR> Exit For<BR> End If<BR> next<BR>End Function<BR><BR>

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## RE: figuring holidays programatically

Labor Day is the first Monday of August:<BR><BR>[code language="VBScript"]Function GetLaborDay(ByVal HolidayYear)<BR><BR>Dim dtOut<BR> dtOut = GetXOccuranceOfWeekdayInMonth(9, HolidayYear, vbMonday, 1)<BR><BR> GetLaborDay = dtOut<BR><BR>End Function[/code]<BR><BR>Memorial Day is the 4th Monday of May:<BR><BR><BR>[code language="VBScript"]Function GetMemorialDay(ByVal HolidayYear)<BR><BR>Dim dtOut<BR> dtOut = GetXOccuranceOfWeekdayInMonth(5, HolidayYear, vbMonday, 4)<BR><BR> GetMemorialDay = dtOut<BR><BR>End Function[/code]<BR><BR>The helper function:<BR>[code language="VBScript"]Function GetXOccuranceOfWeekdayInMonth(ByVal TheMonth, ByVal TheYear, ByVal TheWeekday, ByVal TheOccurance)<BR><BR>Dim dtOut<BR>Dim dtLoop<BR>Dim iCnt, _<BR> iOccuranceCnt<BR> dtLoop = DateSerial(TheYear, TheMonth, 1)<BR> <BR> While IsDate(dtOut) = False And Month(dtLoop) = TheMonth<BR> If Weekday(dtLoop) = TheWeekday Then<BR> iOccuranceCnt = iOccuranceCnt + 1<BR> <BR> If iOccuranceCnt = TheOccurance Then<BR> dtOut = dtLoop<BR> End If<BR> End If<BR> <BR> dtLoop = DateAdd("d", 1, dtLoop)<BR> Wend<BR> <BR> GetXOccuranceOfWeekdayInMonth = dtOut<BR><BR>End Function[/code]<BR>

3. Senior Member
Join Date
Dec 1969
Posts
115

## Thanks

Thanks God, works great. much cleaner code than my mess, LOL.

4. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## I went and figured out..

.. how to handle a bunch of holidays throughout the year.

5. Senior Member
Join Date
Dec 1969
Posts
96,118