Real Software Forums
http://forums.realsoftware.com/

Calculate Major U.S. Holidays
http://forums.realsoftware.com/viewtopic.php?f=21&t=44157
Page 1 of 1

Author:  DaveS [ Sat May 26, 2012 1:06 pm ]
Post subject:  Calculate Major U.S. Holidays

FUNCTION HOLIDAY(year as integer,Holiday_Name as string) as DATE
Dim dt As New date
Dim h As Integer
Dim i As Integer
Dim j As Integer
Dim l As Integer
Dim m As Integer
Dim d As Integer
//
If year<1900 Or year>2099 Then Return Nil
dt.day=1
Select Case holiday_name
Case "NEW YEAR"
dt.month=1
//
Case "4th of July" ' duh
dt.month=7
dt.Day=4
//
Case "Christmas"
dt.month=12
dt.day=25
//
Case "LABOR DAY" ' 1st Monday in September
dt.month=9
First_Monday(dt)
//
Case "Martin Luther King","MLK" ' 3rd Monday in January
dt.month=1
First_Monday(dt)
dt.day=dt.day+14
//
Case "PRESIDENTS DAY" ' 3rd Monday in February
dt.month=2
First_Monday(dt)
dt.day=dt.day+14
//
Case "COLUMBUS DAY" ' 2nd Monday in October
dt.month=10
First_Monday(dt)
dt.day=dt.day+7
//
Case "VETERANS DAY" ' 4th Monday in October
dt.month=10
First_Monday(dt)
dt.day=dt.day+21
//
case "THANKSGIVING" ' 4th Thursday in November
dt.Month=11
First_Monday(dt)
dt.day=dt.day-4 ' back up to thursday
if dt.Month<>11 then dt.day=dt.day+7 ' 1st Thurs
dt.day=dt.day+21
//
case "MEMORIAL DAY" ' Last Monday in May
dt.month=6 ' get 1st Monday in JUNE
First_Monday(dt)
dt.day=dt.day-7 ' back up to last Monday in May
//
Case "EASTER"
H = (24 + 19*(year Mod 19)) Mod 30
I = H - (H\28)
J = (year + year\4 + I - 13) Mod 7
L = I - J
m = 3 + (L + 40)\44
d= L + 28 - 31*(m\4)
dt.year=year
dt.month=m
dt.day=d
//
Case "GOOD FRIDAY"
dt.totalseconds=HOLIDAY(year,"EASTER").TotalSeconds
dt.day=dt.day-2
//
Case "ASH WEDNESDAY"
dt.totalseconds=HOLIDAY(year,"EASTER").TotalSeconds
dt.day=dt.day-46
Case Else
Return Nil
End Select
Return dt
END FUNCTION


SUB First_Monday(byref dt AS Date)
Dim d As Integer
d=dt.DayOfWeek ' 1=Sun
Select Case dt.DayOfWeek
Case 1
d=1
Case 2
d=0
Case Else
d=9-d
End Select
dt.day=dt.day+d
END SUB

Author:  simulanics [ Sat May 26, 2012 9:48 pm ]
Post subject:  Re: Calculate Major U.S. Holidays

Awesome :-) Here's a complete list of holiday and date conversions including Gregorian calculations and hebrew holidays:-) ...very little needed to port to RB

http://www.tek-tips.com/faqs.cfm?fid=5185

Thanks!

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/