I am trying to convert dates in the form Year-WeekNumber to datetimes using strptime. According to the docs I should do it with the formatting code %Y-%W
, however when I do this it always returns January 1st.
>>> datetime.datetime.strptime('2020-11', '%Y-%W')
datetime.datetime(2020, 1, 1, 0, 0)
>>> datetime.datetime.strptime('2020-1', '%Y-%W')
datetime.datetime(2020, 1, 1, 0, 0)
>>> datetime.datetime.strptime('2020-31', '%Y-%W')
datetime.datetime(2020, 1, 1, 0, 0)
Why does strptime give the wrong output? Is there another method I can use to handle this conversion?
Edit: Note the suggested question Python - Get date from day of week, year, and week number doesn't fit as it doesn't explain why %Y-%W
wasn't suitable for converting and the input syntax it was using was different.