Finding third Wednesday each month (1 Viewer)

rpadams

Registered User.
Local time
Today, 04:10
Joined
Jun 17, 2001
Messages
111
This seems easy, but I can't get it right. I need to find the DATE of the THIRD Wednesday each month. (Actually, it is for a query criteria that will return TRUE if Now() is a "third Wednesday.") The problem is that depending on the month starting date, number of days in month prior etc. this date can be either in the 3rd or 4th week. Also, you can't just add 28 days to the prior month because it can vary.
 

raskew

AWF VIP
Local time
Today, 03:10
Joined
Jun 2, 2001
Messages
2,734
Hi -

The following function, developed to assist in determining yearly holidates, should give you what you've specified.

HTH - Bob
Code:
Function NthXDay(pdate As Variant, _
                 pWDay As Integer, _
                 pIncrement As Integer) As Date
'***************************************************************
'Purpose:   Some holidays fall on the Nth XDay of the month.
'           Given a month, year, weekday and increment (e.g.
'           1st, 3rd, last) this function returns the specific
'           date.
'Coded by:  raskew
'Inputs:    ? NthXDay(dateserial(year(date), 11, 1),vbMonday, 3)
'Note:      Use 6 to indicate the last increment, since no month
'           will have 6 of any specified weekday.
'***************************************************************

Dim dteDate As Date
Dim newDate As Date

    dteDate = DateValue(pdate)
    
    'adjust the increment if it's more than 6
    pIncrement = IIf(pIncrement > 6, 6, pIncrement)
    
    
    'determine first day of given month
    dteDate = DateSerial(Year(dteDate), Month(dteDate), 1)
    
    'determine first specified day of given month, e.g. vbSunday
    newDate = dteDate - WeekDay(dteDate) + pWDay + IIf(WeekDay(dteDate) > pWDay, 7, 0)
    
    'determine the nth specified day of given month
    newDate = DateAdd("d", 7 * (pIncrement - 1), newDate)
    
    'if the resulting calculation is greater than the length of the
    'specified month, cycle backwards to the last specified day of
    'the month
    Do While Month(newDate) <> Month(dteDate)
       newDate = newDate - 7
    Loop
    
    NthXDay = newDate

End Function
 

Bat17

Registered User.
Local time
Today, 09:10
Joined
Sep 24, 2004
Messages
1,687
I think this will work, you will be able to find out tommorow:)
Code:
Function thirdWed() As Boolean
Dim dDate As Date
dDate = DateSerial(Year(dDate), Month(dDate), 1)
Do While Weekday(dDate, 1) <> 4
    dDate = dDate + 1
Loop
dDate = dDate + 14
If dDate = DATE Then thirdWed = True
End Function

Peter
 

raskew

AWF VIP
Local time
Today, 03:10
Joined
Jun 2, 2001
Messages
2,734
And what if you want to find the second Thursday or the fourth Friday?

Bob
 

Bat17

Registered User.
Local time
Today, 09:10
Joined
Sep 24, 2004
Messages
1,687
(Actually, it is for a query criteria that will return TRUE if Now() is a "third Wednesday.")
He just wanted true or false for third Wednesday :)

Peter
 

Users who are viewing this thread

Top Bottom