Avatar of Hiroyuki Tamura
Hiroyuki TamuraFlag for United States of America

asked on 

MS Access Weekly query

I'm trying to create a weekly query. from Mon to Sun.
I tried format ([time],"ww") but can't understand how it works.
Microsoft Access

Avatar of undefined
Last Comment
Hiroyuki Tamura
Avatar of PatHartman
PatHartman
Flag of United States of America image

I'm not sure where you are going with this so I just made a sample from one of my tables.

SELECT Year([LastChangeDT]) AS ChngYear, Format([LastChangeDT],"ww") AS ChngWeek, Count(*) AS Expr1
FROM tblChangeDT
GROUP BY Year([LastChangeDT]), Format([LastChangeDT],"ww");

This query returns:
User generated image
Avatar of Hiroyuki Tamura

ASKER

Thank you. How does "ww" define a week?
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of PatHartman
PatHartman
Flag of United States of America image

Gus' function returns 2017W13 for today's date.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Problem is, that Format and DatePart don't always get week 53 right. Also, both week 1 and 52/53 can belong to either a calendar year before or after New Year. Thus, you need that year part as well to sort and group correctly when data spans calendar years.

/gustav
Avatar of PatHartman
PatHartman
Flag of United States of America image

That's why I included Year in my query example.  Since year does not divide cleanly into weeks, it is necessary to decide how to handle the first week of the year when it doesn't start on the first day of the week and that also impacts the definition of the Last week of the year.  The ISO method may be what Tamura wants but in this case, the correct answer is actually what satisfies the business users.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Who knows? Questioneer is  silent.

/gustav
Avatar of Hiroyuki Tamura

ASKER

Thank you, all. I'm trying to add ISO method.
is this the right way?
User generated image
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Yes.
Avatar of Hiroyuki Tamura

ASKER

Thank you all
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo