Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Doing this, I get an error:

ValueError: time data '%Y-%m-%d %H:%M:%S' does not match format
 '2012-11-14 14:32:30'
like image 770
Gasper Avatar asked Nov 14 '12 14:11

Gasper


1 Answers

The correct syntax is:

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

so first the string, then the 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'
like image 176
eumiro Avatar answered Oct 24 '22 20:10

eumiro