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

On parsing datetime, ValueError: time data does not match format

I have date time in the format YYYY/DOY/HHMM

DOY = Day of year

I tried to parse as follows.

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

from datetime import datetime
s = "1929/189/1820"
res = datetime.strptime(s, "%y/%j/%H%M")
print (res)

ValueError: time data ‘2029/199/1820’ does not match format ‘%y/%j/%H%M’.

>Solution :

The Y for year should be capitol

This should fix it.

datetime.strptime(s, "%Y/%j/%H%M")

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