Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error message when using datetime to convert a string to datetime object

The code is as follows:

for i in range(0,len(df)):
    df['date'][i] = datetime.strptime(df['date'][i], '%y-%m-%d %H:%M:%S')

I got the error message:

time data ‘2019-12-06 09:00:00’ does not match format ‘%y-%m-%d %H:%M:%S’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I don’t know why it gives me this message and how to handle it?

>Solution :

The issue is %y, which truncates the year by its last two digits. You need %Y instead, which will give you four digits for the year.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading