YYYYWW date format with criteria (1 Viewer)

Baz248

New member
Local time
Today, 12:01
Joined
Jan 15, 2019
Messages
2
Hi All,
First time posting but I would like to thank you for all the questions you have unknowingly answered.I am pretty new using access and these forms have been really helpful. I am having an issue that I can’t seem to find a solution to.

I am receiving some data that comes in with a date in text in the format of YYYY in column A and Week number in text in the format of WW in column B. I am trying to make a query that combines them into one column and something I can run some criteria against. For example, show me all for previous 4 weeks.

My attempt:(I am using the Expression Builder)

Field: DateAdd("ww",
![Week #]-1,DateSerial(
![Year],1,5))

Criteria: Between Format(DateAdd("ww",-1,Date()),"yyyyww") and Format(DateAdd("ww",-4,Date()),"yyyyww")

The problem is the result will include 20186-20189 along with 201851 - 20192 when I would expect for it to only return 201851 - 20192. Today being WK3 of 2019. I suspect this is because of the format in my Field.

Year Week Attempt today 4weeks past
2018 6 20186 20193 201851
2018 7 20187 20193 201851
2018 8 20188 20193 201851
2018 9 20189 20193 201851
2018 51 201851 20193 201851
2018 52 201852 20193 201851
2019 1 20191 20193 201851
2019 2 20192 20193 201851

How can I make Access realize that 2018 is a year in date format, 52 is a WK in date format, combine them into YYYYWW format so that I can run some criteria against?
 

plog

Banishment Pending
Local time
Today, 14:01
Joined
May 11, 2011
Messages
11,638
2 options: Either make your data resolve to dates or build your own Date functions to compare your "dates".

1. Means you build a query on your table, bring in all its fields, then make a calculated field that is a date that reflects the first date of the week your Year and Week values represent. Then, you can build a query on top of that query to do your comparisons using the built-in Date functions.

2. Means you build your own function (e.g. WeeksDifference()) that takes your special "dates" and does the comparison for you and returns the value you need.

With all that said Week comparison is funky. You do know that every year spans at least 53 weeks right? (365 / 7 = 52 Remainder 1) . What happens with that 53rd week that doesn't have a full 7 days?
 

JHB

Have been here a while
Local time
Today, 21:01
Joined
Jun 17, 2012
Messages
7,732
Without testing it, I think your problem is that the data for year and week is converted to text.
Either make it into number values or insert a 0 for all weeks between 1-9.
Ex: 20181 must be 201801 and 20182 = 201802.
 

Baz248

New member
Local time
Today, 12:01
Joined
Jan 15, 2019
Messages
2
Thank you both for your replies.
Plog, I think you are correct. What I ended up doing is converting the YearWK to a date then running my criteria against that. I know it’s a little funky to work in WK’s and doing it in access but it’s the best I have until I can get my data daily and move it into some reporting software.

Field: DateAdd("ww",((
![Year] & Format(
![Week #],"00")) Mod 100)-1,DateSerial((
![Year] & Format(
![Week #],"00"))\100,1,1))

Criteria: Between DateAdd("d",Date(),- 36 ) And DateAdd("d",Date(),-6)

Edit In Red
 
Last edited:

Users who are viewing this thread

Top Bottom