Reputation: 1854
So I have test_date1 = "2017-07-21-10-20"
and I want to convert to
day1 = datetime.strptime(test_date1, "%y-%m-%d-%h-%M")
but I get the following error :
time data '2017-07-21-10-20' does not match format '%y-%m-%d-%H-%M'
What are the proper fields for hours and minutes?
Upvotes: 0
Views: 54
Reputation: 671
Use capital Y
for "century" year.
datetime.strptime(test_date1, "%Y-%m-%d-%H-%M")
Reference: http://strftime.org/
%Y Year with century as a decimal number. 2013
Upvotes: -1
Reputation: 3135
Use capital H for hour. Check this:
datetime.strptime(test_date1, "%Y-%m-%d-%H-%M")
See https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
Upvotes: 2
Reputation: 2489
below code is working
datetime.strptime("2017-07-21-10-20",'%Y-%m-%d-%H-%M')
Upvotes: 1