Search code examples
pythonpython-3.xdatetimestrptime

Can't turn datetime string into datetime object - ValueError


date_time_str = data['date']
date_time_obj = dt.datetime.strptime(date_time_str, "%Y-%m-%d %H:%M:%S")
print(date_time_obj)

I get this error:

ValueError: time data 'date' does not match format '%Y-%m-%d %H:%M:%S

But the string datetime is the same exact format as I formatted above:

"2020-08-30 20:29:42"

Solution

  • I think the problem is not this dt.datetime.strptime(date_time_str, "%Y-%m-%d %H:%M:%S"). It looks like data['date'] is a time data.