 |
|
 |
stickleprojects Level: Moderator

 Registered: 09-09-2002 Posts: 891
|
Re: Date Function, 1st, 2nd Thursday ect..
Hi,
The following function works in VB6 and Access 2003 (so, I assume it works in access 2002 too):
Option Compare Database
Public Function GetCountInMonth(dt As Date, Optional WhatDay As VbDayOfWeek = vbThursday) As Integer
' Return the week number of the month, that this date occurs on
Dim dtFirst As Date
Dim intOccurence As Integer
' This is not the same day of the week, so exit
If Weekday(dt) <> WhatDay Then Exit Function
' get the first occurence in the month
dtFirst = CDate("01 " & Format(dt, "mmm") & " " & Year(dt))
While Weekday(dtFirst) <> WhatDay
dtFirst = dtFirst + 1
Wend
' Add 7 days to this until we get a next month, or > dt
While dtFirst <= dt
intOccurence = intOccurence + 1
dtFirst = DateAdd("ww", 1, dtFirst)
Wend
GetCountInMonth = intOccurence
End Function
Usage:
Parameter 1 is the date you want to check
Parameter 2 is the weekday you want to compare it with
ie.
to find if the date is the first thursday, then:
iif ( GetCountInMonth(table.date, vbThursday ) = 1, 1 ,0)
to find if the date is the 4th wednesday:
iif ( GetCountInMonth(table.date, vbWednesday ) = 4, 1 ,0)
Hope this helps,
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
|
|
12-08-2005 at 11:44 AM |
|
|
|
|
 |
 |