Skip to content
Advertisement

Convert week number and year to a date in Access-SQL?

In Microsoft Access, I have a table where number of hours worked per weekday are associated to a project number, ISO-week number and year. Simplified, it looks like this:

ProjectID WeekNumber YearNumber Monday Tuesday
1 1 2022 5 6
1 2 2022 7 8

I am trying to set up a query where all weekday columns (monday to sunday) are “merged” into one column and the week and year numbers are converted to dates. It should look like this:

ProjectID Date HoursPerDay
1 03.01.2022 5
1 04.01.2022 6
1 10.01.2022 7
1 11.01.2022 8

I managed to merge all weekday columns into one column using a UNION query:

The result looks like this:

ProjectID WeekNumber YearNumber HoursPerDay
1 1 2022 5
1 1 2022 6
1 2 2022 7
1 2 2022 8

But I am stuck converting the iso-week and year number to a date. Is this at all possible in Access-SQL?

I found this question on Stackoverflow and went through the date/time functions that Microsoft lists for Access but could not get it to work.

Any help is highly appreciated.

EDIT: A community member has suggested a possible duplicate of this question, but I am looking for a solution that I can use in an Access-SQL query, so the suggested duplicate does not help me, as it suggests a VBA based solution.

Advertisement

Answer

This is not so simple, as the ISO years rarely are in sync with calendar years.

But this function will do:

However, it uses a series of supporting functions, like:

and several more – way too much to post here.

So, please refer to my project at GitHub, VBA.Date, for the modules holding the full code.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement