Reputation: 1854
I am reading dates from csv to python in the form of 2017-01-04. I am trying to process dates like
from datetime import datetime
day1 = datetime.strptime(date1, date_format)
where I use date_format = "%y-%m-%d"
However, when I process the data, I get the error:
time data '2017-01-04' does not match format '%y-%m-%d'
What should it be?
Upvotes: 2
Views: 82
Reputation: 149
You can run it-This code run successfully and print-2017-01-04 00:00:00
from datetime import datetime
day1 = datetime.utcnow().strptime('2017-01-04', '%Y-%m-%d')
print(day1)
Upvotes: 0
Reputation: 10631
Y - Year with century as a decimal number.
y - Year without century as a zero-padded decimal number.
Therefore, you should use Upper Y.
For more information about the formats, you can see it all in here
Upvotes: 4
Reputation: 3634
Something like :
from datetime import datetime
day1 = datetime.utcnow().strptime('2017-01-04', '%Y-%m-%d')
Upvotes: 0