time data does not match format (match)

I got the following error:

time data '23-MAY-2019 12:49:08' does not match format '%d-%m-%yyyy %H:%M:%S' (match)

this is my code:

dfbaseline['Date'] = pd.to_datetime(dfbaseline['Date'], format='%d-%m-%yyyy %H:%M:%S')

What’s wrong?

>Solution :

There are two problems with your date format.

pd.to_datetime(dfbaseline['Date'], format='%d-%m-%yyyy %H:%M:%S')
  • %m is used to match Month in a zero-padded decimal number
    (01 to 12).
  • %y will match year without century as a zero-padded decimal number(00, 01, …, 99)

So you have to change,

  • %b to match Month in a locale’s abbreviated name(Jan/Feb/Mar etc)
  • %Y to match Year with century as a decimal number(0001, 0002, …, 2013, 2014, …, 9998, 9999)
pd.to_datetime(dfbaseline['Date'], format='%d-%b-%Y %H:%M:%S')

See strftime() and strptime() Format Codes for more information.

Leave a Reply