Finding the 3rd Friday of every month

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anybody know the code to determine what the date is of the 3rd Friday of every month is?
 
SHIPP said:
Does anybody know the code to determine what the date is of the 3rd Friday of every month is?

Public Function ThirdFriday(DT As Date) As Date
Dim DL As Date
Dim DA As Integer
DL = DateSerial(Year(DT), Month(DT), 1)
DA = WeekDay(DL, 7)
ThirdFriday = DateAdd("d", 21 - DA, DL)
End Function
 
Well, the 3rd Friday could be from the 15th to the 21st.

Public Function ThirdFriday(intMonth As Integer, intYear As Integer) As Date
Dim i As Integer, dteTempDate As Date
For i = 15 To 21
dteTempDate = DateSerial(intYear, intMonth, i)
If WeekDay(dteTempDate) = vbFriday Then
ThirdFriday = dteTempDate
Exit For
End If
Next i
End Function

--
Wayne Morgan
MS Access MVP


SHIPP said:
Does anybody know the code to determine what the date is of the 3rd Friday
of every month is?
 
Does anybody know the code to determine what the date is of the 3rd Friday of every month is?

Never write code when you can build a table, that's what *I* always
say.

SELECT Cal_Date, Cal_DOW, Cal_DOW_Ordinal
FROM Calendar
WHERE (Cal_DOW = 'Fri' AND
Cal_DOW_Ordinal = 3);

I left the structure of the calendar table as an exercise.

I used Excel to calculate the values once, put them under revision
control, then used a text-processing tool to generate SQL INSERT
statements from the values.
 
Back
Top