Reputation: 97
I have to use datetime
to change the a date from str
to date
but I'm getting an unexpected result:
strd = "2020-02-06"
dated = datetime.strptime(strd, '%Y-%M-%d').date()
print(dated)
I expect the result should be 2020-02-06
but the output is 2020-01-06
.
What is causing this?
Upvotes: 1
Views: 698
Reputation: 137268
%M
is for minutes, not months. Since you aren't providing a value for months you're getting the default.
Use %m
instead:
dated = datetime.strptime(strd, '%Y-%m-%d').date()
# ^
Upvotes: 3