Calculate Floating Holidays

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/70619?pagenum=1
04 November 2025, 15:09

Topic


TastyNutz
Calculate Floating Holidays
17 October 2013, 18:26


Anyone have code to calculate 'floating' holidays which always fall on X instance of Y day of the week during Z month, such as Thanksgiving?

 

Replies ...


HuwR
18 October 2013, 04:11


There is a floating holidays add on for the calendar mod, you could probably use that code as a basis for what you want

Calendar Mod on SnitzBitz
Carefree
18 October 2013, 09:50


It's fairly simple to do. Calculate the last day of the previous month, determine which day of the week it is, proceed x days to reach the day you want, then increment by given number of weeks.
Thanksgiving (4th Thursday in November) ...
Code:
dateCursor = DateSerial(DatePart("yyyy",dateCursor) + 1,10,31)
Do Until Weekday(dateCursor) = vbThursday
dateCursor = DateAdd("d", 1, dateCursor)
Loop
dateCursor = DateAdd("ww", 3, dateCursor)
President's Day (3d Monday in February) ...
Code:
dateCursor = DateSerial(DatePart("yyyy",dateCursor) + 1,1,31)
Do Until Weekday(dateCursor) = vbMonday
dateCursor = DateAdd("d", 1, dateCursor)
Loop
dateCursor = DateAdd("ww", 2, dateCursor)

Assuming you want to calculate the date during 2014, you would set the initial value of dateCursor to Now(). So to get Thanksgiving Day in 2014, try this:
Code:

<%
dateCursor = DateSerial(DatePart("yyyy",Now()) + 1,10,31)
Do Until Weekday(dateCursor) = vbThursday
dateCursor = DateAdd("d", 1, dateCursor)
Loop
dateCursor = DateAdd("ww", 3, dateCursor)
Response.Write "Thanksgiving Day: " & dateCursor
%>
Notice the bit in red. That says to add 1 year ("yyyy") to the current year. To get Thanksgiving for this year, change it to a 0; for 2015, make it a 2; etc.
TastyNutz
18 October 2013, 17:18


Thanks guys.
© 2000-2021 Snitz™ Communications