I had an error when I execute the following code:
format = '%m/%d/%y/%H:%M:%S'
t = datetime.strptime(result[a][b], format) ### result [a][b] contains a string
I use %y because the year contain only last two digits. This code works perfectly for all cases except those in which day and month are the same. For eg: 02/11/11 gives an error but 11/11/16 doesn't. Does anyone know why this happens?
datetime error in Python
Re: datetime error in Python
It would help to see the whole code you used to produce the error and the error itself. This works perfectly fine for me in both Python2.7 and Python3.5:
Syntax: Select all
>>> from datetime import datetime
>>> datetime.strptime('11/11/11/12:22:17', '%m/%d/%y/%H:%M:%S')
datetime.datetime(2011, 11, 11, 12, 22, 17)
>>> datetime.strptime('02/11/11/12:22:17', '%m/%d/%y/%H:%M:%S')
datetime.datetime(2011, 2, 11, 12, 22, 17)
>>> datetime.strptime('11/11/16/12:22:17', '%m/%d/%y/%H:%M:%S')
datetime.datetime(2016, 11, 11, 12, 22, 17)
Return to “General Discussion”
Who is online
Users browsing this forum: No registered users and 15 guests