ValueError: time data '% Y-% m-% d% H:% M:% S' does not match the format '2012-11-14 14:32:30'

I am trying to convert the object '2012-11-14 14:32:30' to datetime.datetime via the datetime.datetime.strptime method using the format string '%Y-%m-%d %H:%M:%S' .

When doing this, I get an error message:

 ValueError: time data '%Y-%m-%d %H:%M:%S' does not match format '2012-11-14 14:32:30' 
+7
source share
1 answer

The correct syntax is:

 datetime.strptime('2012-11-14 14:32:30', '%Y-%m-%d %H:%M:%S') 

so first a line, then a format.

Read aloud:

 ValueError: time data '%Y-%m-%d %H:%M:%S' does not match format '2012-11-14 14:32:30' ValueError: time data '2012-11-14 14:32:30' does not match format '%Y-%m-%d %H:%M:%S' 
+18
source

All Articles