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

We Are Going To Discuss About ValueError: time data ’02/03/2022′ does not match format ‘%d/%m/%y ‘. So lets Start this Python Article.

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

  1. How to solve ValueError: time data '02/03/2022' does not match format '%d/%m/%y '

    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')

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

    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')

Solution 1

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')

Original Author Giulio Mattolin Of This Content

Solution 2

The %y refers to just the last 2 digit of the year, not the whole year as you have in the example.

20/03/21 is in format '%d/%m/%y while
20/03/2021 is in format '%d/%m/%Y(note the capital Y) therefore you just need to update the code as following

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 ')

You can find an useful table of each flag on this link

Original Author DaSim Of This Content

Solution 3

This error indicates that format and input are not aligned.
In this example the input: ’02/03/2022′,
does not match format ‘%d/%m/%y’

Why?
Since %y is a year with two letter, such as ’22’ rather than ‘2022’.
BTW, the rest of the input does match the format.

Use this link to verify the format in correct:
https://www.geeksforgeeks.org/python-datetime-strptime-function/

Original Author Nir Kahila Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment