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?
CodePudding user response:
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 format(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.
CodePudding user response:
You can check out here, Different characters for formatting a DateTime as a string - https://www.ibm.com/docs/en/app-connect/11.0.0?topic=function-formatting-parsing-datetimes-as-strings#:~:text=Characters for formatting a dateTime as a string