xth weekday of the month (1 Viewer)

Status
Not open for further replies.

Sleekmac

Registered User.
Local time
Today, 08:43
Joined
Sep 25, 2006
Messages
34
Don't know if anyone but me will find this useful but I had to write a function to calculate what the third Wednesday of the month of a date argument is. For example, if the argValue=8/2/07, the function returns the date of the third Wed of August, which is 8/15/07.

Code:
Function thirdWedofMonth(dte As Date) As Integer
Dim thisMonth As Integer, thisDay As Integer, thisYear As Integer
thisMonth = Month(dte)
thisDay = Day(dte)
thisYear = Year(dte)
If Weekday(DateValue(thisMonth & "/" & 15 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 15
If Weekday(DateValue(thisMonth & "/" & 16 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 16
If Weekday(DateValue(thisMonth & "/" & 17 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 17
If Weekday(DateValue(thisMonth & "/" & 18 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 18
If Weekday(DateValue(thisMonth & "/" & 19 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 19
If Weekday(DateValue(thisMonth & "/" & 20 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 20
If Weekday(DateValue(thisMonth & "/" & 21 & "/" & thisYear)) = vbWednesday Then thirdWedofMonth = 21
End Function

This code is based on the fact that the third Wed of any month must be between the 15th and 21st inclusive. So the code could be adapted to any desired weekday by changing those values.
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom