Jun-30-2020, 02:03 PM
Hello there,
I am trying to convert a calendar week into the first and last day of that week.
So for example I am searching for the start and end date of the 24th calendar week of 2020 and the programm should tell me that the first day is the 8.06. and the last day of the week is 14.06.
Sadly the programs thinks that I mean the 24th of december 2019 and I dont know how to fix this.
My code looks as this:
I am trying to convert a calendar week into the first and last day of that week.
So for example I am searching for the start and end date of the 24th calendar week of 2020 and the programm should tell me that the first day is the 8.06. and the last day of the week is 14.06.
Sadly the programs thinks that I mean the 24th of december 2019 and I dont know how to fix this.
My code looks as this:
from datetime import datetime, timedelta date_y = "2020-" date_w = "24" date_str = date_y + date_w date_obj = datetime.strptime(date_str, '%Y-%W') # First day of the week start_of_week = date_obj - timedelta(days=date_obj.weekday()) # Last day of the week end_of_week = start_of_week + timedelta(days=6) print(start_of_week) print(end_of_week)