Skip to content
Advertisement

Getting all starting dates of year 2020 with ISO week frequency

I’d like to create a list of dates each of which represents the starting date of ISO week N of year 2020.

Something like:

JavaScript

I have obtained something similar using timedelta(weeks=1), and adding this to my START_DATE (date(2020, 1, 1)), but the dates I obtain are not correct.

I know I could simply change my START_DATE to be date(2019, 12, 30), but I would like to know if there is a more robust approach to derive all the week starting dates present in a given year.

Just for the sake of clarity, here is what i am doing now:

JavaScript

Advertisement

Answer

For the first interval, find the weekday of the starting date and subtract this from a full week. After the first step, set the interval back to one week.

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