Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Calculate Floating Holidays
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TastyNutz
Junior Member

USA
251 Posts

Posted - 17 October 2013 :  18:26:26  Show Profile  Visit TastyNutz's Homepage  Reply with Quote
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?


PowerQuad Disability Support Forum

Edited by - TastyNutz on 17 October 2013 18:30:17

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 18 October 2013 :  04:11:48  Show Profile  Visit HuwR's Homepage  Reply with Quote
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

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 18 October 2013 :  09:50:15  Show Profile  Reply with Quote
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.

Edited by - Carefree on 18 October 2013 11:05:13
Go to Top of Page

TastyNutz
Junior Member

USA
251 Posts

Posted - 18 October 2013 :  17:18:00  Show Profile  Visit TastyNutz's Homepage  Reply with Quote
Thanks guys.


PowerQuad Disability Support Forum
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000 Version 3.4.07