The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
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?
Last edited by TastyNutz on 17 October 2013, 18:30
Posted
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
Calendar Mod on SnitzBitz
Posted
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) ...President's Day (3d Monday in February) ...
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:
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.
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)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
%>
Last edited by Carefree on 18 October 2013, 11:05
Posted
Thanks guys.
Email Member
Message Member
Post Moderation
FileUpload
If you're having problems uploading, try choosing a smaller image.
Preview post
Send Topic
Loading...