Identifying the week of the month in a Access Query

How do I get an access query to say the week of the month based on a date field in that query.  Date field is simply named [Date]

Of course weeks don't fit neatly into months. August 2015 starts on a Saturday; is August 1 "Week 1" and August 2 part of "Week 2"? August 30 and 31 are a Sunday and Monday - are they Week 6?

What's the context? How will this number be used?

John W. Vinson/MVP

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

First, Date is a reserved word in Access and shouldn't be used as an object name. 

Second, as John says you need to define what constitutes a week. Is week 1 the first week that starts with a Sunday, or is the week of the first day or what?

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I would say even if the first day of the month is a friday, that friday to saturday is week 1 just for reporting purposes.  So there could be 6 weeks in the month.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You would need to do this in a custom function. First check what the day of the week the first day is. Then use that to find the first day of the first full week. From there you should be able to calculate whihc week of the month a date is in.
Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I have done something similar ... designed a staff scheduling program for my wife's work.

They operate on a 4-week shift rotation, and used to just keep doing it out by hand on a monthly calendar.

The example in the picture above shows that Jan 1 - 3, 2015 are days in week 3. Sunday Jan 4 is the first day of "Week 4", and so on. 

My Friend Google came up with a  date functions that I use to determine the week number based on picking a starting date. (#6/13/2004# in her case)

Public Function fGetWeek(TheDate As Date) As Integer
fGetWeek = (DateDiff("ww", #6/13/2004#, TheDate) Mod 4) + 1
End Function

'Author: Kurt A. Fisher <*** Email address is removed for privacy ***> 11/6/97
'No copyright asserted. No warranty for fitness of use is
'expressed or implied.

'Acknowledgements:
'Getz. 1997. "Working with Dates". Chapter 2 in VBA Developer 's Handbook. Sybex.
'MicroSoft KnowledgeBase Articles:
' Q88657 Functions for Calculating and Displaying Date/Time Values (8/29/97)

This is just ONE of many very useful Date Functions in the code that I found.

I can post or send the rest if you like.

-- Finally allowed to use Access at work! So excited! --

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Try the following expression:

 

DatePart("ww",[TheDate])-DatePart("ww",DateSerial(Year([TheDate]),Month([TheDate]),1))+1

_____________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

23 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 18, 2024 Views 5,848 Applies to: