Reputation: 31
n=10
I want to get the week commencing date of the 10th week of the current year (2022), i.e., 3/7/2022. How can this be done using datetime functions?
Upvotes: 1
Views: 37
Reputation: 3030
You need to use the %W directive, but you also need to specify what the start day is of the week and of course the year.
Example:
from datetime import datetime
print(datetime.strptime("10-2022-1", "%W-%Y-%w"))
Result:
2022-03-07 00:00:00
Datetime formats: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
Upvotes: 1