I am using the SQLite3 module within Python and I currently have a table that stores a "date" as datetime. However, whenever I try to retrieve that date from the table and compare it to today's date (eg today = datetime.datetime.today()), I get an error that says:
if row > today:
TypeError: can't compare datetime.datetime to tuple"
Here is a snippet of the code that I am having trouble with:
for row in con.execute('select time_date as "d [datetime]" from fault_record'):
if row < today:
print row
I am stumped on how to convert the tuple date to a datetime?
Thanks!
Rows are returned as tuples of columns, even if there's only one column.
Changing
for row in con.execute('select time_date as "d [datetime]" from fault_record'):
to
for date, in con.execute('select time_date as "d [datetime]" from fault_record'):
will iterate over the dates, instead of the row tuples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.