Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

group by number of week of the month

Status
Not open for further replies.

jhrs

Technical User
Oct 7, 2003
10
PE
hi, is there a function in access to group by the number of week in a month, I have found one but it is for the whole year (53 weeks) and if i could count from the first day of that month, example if the month begins on friday it would be the first week til next thursday

Thanks a lot
 
You could make your own function using DateDiff.

Code:
Function WeekInMonth(dtMyDate As Date) As Integer

Dim intFirstDay As Integer, dtFirstDay As Date

If IsDate(dtMyDate) Then
    dtFirstDay = Month(dtMyDate) & "/01/" & Year(dtMyDate)
    intFirstDay = Weekday(dtFirstDay)
    WeekInMonth = DateDiff("w", dtFirstDay, dtMyDate, intFirstDay) + 1
Else
    WeekInMonth = 0
End If

End Function

Then, with your SELECT statement...
SELECT WeekInMonth(YourDateField) From YourTable
GROUP BY WeekInMonth(YourDateField)


Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top