Skip to content
Advertisement

Convert ’01-Feb-15′ to Python date 01/02/2015 [closed]

tbk = ’01-Feb-15′

I wish to convert to datetime so that tbk = 01/02/2015 I have tried the following:-

  tbk = datetime.datetime.strptime(tbk, '%d-%b-%y').strftime('%d/%m/%Y')

I receive the following error:- ValueError: time data ’01-Feb-15′ does not match format ‘%d-%b-%Y’

What am I doing wrong?

Advertisement

Answer

In your error message you have capital Y which implies that you try to use format ‘%d-%b-%Y’ instead of ‘%d-%b-%y’ that you wrote on the example. For me, the example worked just fine.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement