Calculate Floating Holidays - نوشته شده در (1446 Views)
Junior Member
TastyNutz
مطلب: 251
251
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?
 پیش‌فرض مرتب‌سازی برای تاریخ DESC به معنی جدیدترین است  
 تعداد در صفحه 
نوشته شده در
Forum Admin
HuwR
مطلب: 20611
20611
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
نوشته شده در
Advanced Member
Carefree
مطلب: 4224
4224
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.
نوشته شده در
Junior Member
TastyNutz
مطلب: 251
251
 
شما باید یک متن وارد کنید