function to return the day that is the third Wednesday of a given month (1 Viewer)

Status
Not open for further replies.

Sleekmac

Registered User.
Local time
Today, 18:32
Joined
Sep 25, 2006
Messages
34
Don't know if anybody but me will find this useful, but here it is. You can change it to any weekday on any interval by changing the values 15-21. (The logic is based on the fact that the third Wed of every month must necessarily be between the 15th and 21st inclusive.)

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
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom