Week commencing day from week number

sdawson

Registered User.
Local time
Today, 06:21
Joined
Apr 22, 2003
Messages
165
I have a query that groups records by date into week numbers using the following expression.

WeekNumber: DatePart("ww",[Date],2)

I would prefer to display the result as the week commencing Monday date.

How?
 
Use the Weekday function along with the DateAdd function to get Monday's date.

Public Function MonDt(Dt As Date) As Date
Dim DtIn As Date
Dim DOW As Byte

DtIn = Dt
DOW = Weekday(DtIn, vbMonday)

MonDt = DateAdd("d", -DOW + 1, Date)

If you are trying to do it as a calculated field in a query, I think it would be something like

MonDt: DateAdd("d", -WeekDay(DateField, vbMonday) + 1, DateField)
 
Last edited:
Looks good.
Thanx.
 
Is it me?

I've put the following expression in expression builder in the Query

Expr1: Date1 + (7 + vbMonday - DatePart("w", Date1 )) Mod 7

and it immediately changes to

Expr1: Date1 + (7 + [vbMonday] - DatePart("w", Date1 )) Mod 7

When I run the Query it asks for a value for [vbMonday].

Same with MonDt: DateAdd("d", -WeekDay(DateField, vbMonday) + 1, DateField) as per grnzrba's reply

and any variation.

Where am I going wrong?

:confused:
 
Last edited:
Sorry about that. I didn't try that last expression. I use the vba function. You could write it as a public function and set the field equal to the function.
 
you cant use vbconstants in the column heading of a query - i think thats why it doesn't like vbmonday
 
Thanks for the clarification, gemma. I just tried it and was wondering why it didn't work. However, I then tried it with 2 replacing the vbMonday, and that did work. (Just make sure the 2 doesn't have brackets around it)
 
Last edited:
Lost here now guys.
Attached is extract of what I'm trying to do
The query byweeknumber does exactly what it says on the tin.
The second query calculates some date but not the wc Monday date.

Any help would be appreciated.
 

Attachments

I apologize.
MonDt = DateAdd("d", -DOW + 1, Date)
should be
MonDt = DateAdd("d", -DOW + 1, Dt)

VBA is seeing Date as Date(). It worked fine for me because I was using during the week to determine what day Monday of that week was.
 
RG,
What's the difference between the straight subtraction and the DateAdd function (besides being neater)? Why bother with DateAdd?
 
They both work. I've gone back and looked at some of my old code and I used both.
 
Well I'll bite the biggest dog in Bury!
Reseverd words. Doh.

Thanks one and all.

Now, anyone know how Coolmax or Drifit technical clothing is best washed?
?:)
 

Users who are viewing this thread

Back
Top Bottom