time_list is a list of tuples, and within each tuple is an integer and two strings, the two strings are in a date format but I want to change them into actual datetime objects. Here's what I do:
for row in time_list:
row[1] = datetime.strptime(row[1], "%Y-%m-%d %H:%M:%S.%5N")
row[2] = datetime.strptime(row[2], "%Y-%m-%d %H:%M:%S.%5N")
delta = row[2] - row[1]
timedelta.append(delta)
I get a different error when I remove the %5N, but that's not what I'm trying to do so I won't bother with that. I do know that %5N is causing the problem. The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\user\Programs\time_database.py", line 50, in search2
row[1] = datetime.strptime(row[1], "%Y-%m-%d%t%H:%M:%S.%5N")
File "C:\Python27\lib\_strptime.py", line 317, in _strptime
(bad_directive, format))
ValueError: '5' is a bad directive in format '%Y-%m-%d %H:%M:%S.%5N'
row[1]androw[2]if they really are tuples.