0

I have a simple three line script that converts a string to a datetime in Python.

from datetime import datetime

mydate='Feb-22-1732'

print(datetime.strptime(mydate,'%b-%dd-%Y'))

But when I run this code, I get an error saying:

ValueError: time data 'Feb-22-1732' does not match format '%b-%dd-%Y'

Can you please help me understand what am I doing wrong here?

Thanks in advance.

SwapnilP
  • 3
  • 2

1 Answers1

0

You don't need to repeat d two times - %d handles two-digit days by definition:

%d - Day of the month as a zero-padded decimal number.

print(datetime.strptime(mydate,'%b-%d-%Y'))
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195