I need to compare dates in this format:
'03/31/2018' # month/day/year
I tried to use the datetime module:
from datetime import datetime as dt
dt.strptime("03/31/2018", "%m/%d/%y")
But I got this error:
ValueError: unconverted data remains: 18
If I use a two digit year:
dt.strptime("03/31/18", "%m/%d/%y")
It works, but in this case I need to compare using the whole four digits year
You need to use a big Y
>>> from datetime import datetime as dt
>>> dt.strptime("03/31/2018", "%m/%d/%Y")
datetime.datetime(2018, 3, 31, 0, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With