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

ValueError: time data '02/03/2022' does not match format '%d/%m/%y '

How to return values only within a specific date range?

I am new to python

My code is:

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


                    for report_date in REPORT_DATE_TYPES:
                        if report_date in result:
                            date = result[report_date].split(' ')[0]
                            date = datetime.strptime(date, '%d/%m/%y ')

but I am getting an error:

raise ValueError("time data %r does not match format %r" %

ValueError: time data ’02/03/2022′ does not match format ‘%d/%m/%y ‘

How to fix this?

>Solution :

To point out the year you need to use %Y and also there is an additional space at the end of the format you gave that it’s not present in the date. Try with date = datetime.strptime(date, '%d/%m/%Y')

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