Dcount week, starting Monday instead of Sunday

Megaduck

Member
Local time
Today, 16:39
Joined
Apr 24, 2020
Messages
30
Hello,

I have the following Dcount query to display weekly record count. Access assumes the week starts on Sunday. I would like to, somehow, adjust this code to count from Monday instead. I thought it would be as easy as adjusting a setting in Options to start weeks on Monday but apparently that isn't an option. :(

Code:
=DCount("*","[Truck Log]","DatePart('ww',[Date]) = DatePart('ww',Date()) And Year([Date]) = Year(Date())")

Any ideas?

Thanks!
 
Subtract 1 day from [Date]


Or maybe Subtract 1 day from Date(). Definitely subtract 1 day from one of those dates.
 
The more I thought about what date to subtract 1 from, the more I got confused. What week and year do you expect the following dates to match with:

January 1 2017 (Sunday)
January 1 2018 (Monday)
January 1 2020 (Wednesday)
 
This seems to have worked for what I need:
Code:
=DCount("*","[Truck Log]","DatePart('ww',[Date],2) = DatePart('ww',Date()) And Year([Date]) = Year(Date())")

Thanks for stirring me in the right direction. Haha.
 
This seems to have worked for what I need:
Code:
=DCount("*","[Truck Log]","DatePart('ww',[Date],2) = DatePart('ww',Date()) And Year([Date]) = Year(Date())")

Thanks for stirring me in the right direction. Haha.
I would have thought you would need the third parameter of DatePart in both functions?
 
I would have thought you would need the third parameter of DatePart in both functions?
I was thinking it may be necessary, too, but I tried it there first and it subtracted the records from Sunday off the week's count. No idea... lol.
 
You should test very carefully. I would use the the third argument in BOTH uses of the function rather than taking a chance. In addition to being sloppy, it will confuse anyone who looks at the code later.
 

Users who are viewing this thread

Back
Top Bottom