Reputation: 187
I have the string "5-11-2019"
in DAY/MONTH/YEAR format, and am doing the following to increment 1 day:
datetime.datetime.strptime(str("5-11-2019"), '%d-%M-%Y') + datetime.timedelta(days=1)
However, instead of getting the result of 2019-11-06
, Python returns 2019-01-06
, removing 10 months, which I cannot for the life of me understand.
Upvotes: 0
Views: 184
Reputation: 16943
Check the “%M”.
Also keep in mind that
%d = Day of the month as a zero-padded decimal number. and %-d = Day of the month as a decimal number. (Platform specific) [From https://strftime.org/]
So either pad your days with 0 or use “%-d”.
Upvotes: 0
Reputation: 5466
You used %d-%M-%Y
as format, but %M
stands for minute
, not month
. You should use %d-%m-%Y
(lower m
).
Upvotes: 1