Python: strptime() formatting

391 views Asked by At

I'm using CPython. This is the code:

import datetime
userBirthday = print("Enter your birthday(DD/MM/YYYY): ")
compBirthday = datetime.datetime.strptime(userBirthday, "%d/%b/%Y")

I get this error message:

ValueError: time data '13/12/2001' does not match format '%d/%b%Y'
1

There are 1 answers

3
mdurant On BEST ANSWER

You wanted this instead:

datetime.datetime.strptime(userBirthday, "%d/%m/%Y")

Where m stands for "month".

Also, checkout dateutil.parser.parse, which can recognise a wide variety of formats.