ValueError: time data '31/10/20' does not match format '%d%m%y'

I keep getting this error, ValueError: time data '31/10/20' does not match format '%d%m%y'

I am a beginner in Python trying to create a countdown calendar from a text file. Below is my code.

enter image description here

1 answer

  • answered 2020-10-29 22:26 Shash Sinha

    Notice the missing / in '%d%m%y' try '%d/%m/%y' instead:

    >>> from datetime import datetime
    >>> date_time_str = '31/10/20'
    >>> date_time_obj = datetime.strptime(date_time_str, '%d/%m/%y')
    >>> date_time_obj
    2020-10-31 00:00:00