Python converts one digit day and month to two digits

I am trying to read and convert the following datetime "6/5/2014 00:09:32"

to "Mon Mar 09 07:07:18 +0000 2015"


d = datetime.datetime.strptime('6/5/2014 00:09:32', '%d/%m/%y %H:%M:%S')


Gives me a traceback with:

ValueError: time data '6/5/2014 00:00:07' does not match format '%d/%m/%y %H:%M:%S'


I tried using% e for single digits as suggested here: but datetime just says, which does not recognize e.

If I'm missing something, it looks like one-digit days and months, this is my problem, but from the documentation ( ) 't see a way get python datetime to read single digit days or months. But that seems silly. What am I missing?

Thank you for your help.


source to share

1 answer

You do 'Y'

n't need 'Y'


In [412]:

d = dt.datetime.strptime('6/5/2014 00:09:32', '%d/%m/%Y %H:%M:%S')
datetime.datetime(2014, 5, 6, 0, 9, 32)


The docs 'Y'

correspond to:

Year with century as a decimal number.

Have you tried 'Y'


Year without century as a decimal number [00.99].



All Articles