Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Calculate Floating Holidays

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!
Before posting, make sure you have read this topic!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
   

T O P I C    R E V I E W
TastyNutz Posted - 17 October 2013 : 18:26: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?
3   L A T E S T    R E P L I E S    (Newest First)
TastyNutz Posted - 18 October 2013 : 17:18:00
Thanks guys.
Carefree Posted - 18 October 2013 : 09:50:15
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) ...
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) ...
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:

<%
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.
HuwR Posted - 18 October 2013 : 04:11:48
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

Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000 Version 3.4.07