2012-02-28 82 views
0

我在Python中使用SQLite3模塊,並且當前有一個表將「date」存儲爲datetime。然而,每當我試圖從表中檢索該日期,並將它與今天的日期(如今天= datetime.datetime.today()),我得到一個錯誤,指出:[TypeError:不能比較datetime.datetime元組]:如何使用Python和SQLite3比較元組值與日期時間值?

if row > today: 

TypeError: can't compare datetime.datetime to tuple"

這裏

for row in con.execute('select time_date as "d [datetime]" from fault_record'): 

if row < today: 
    print row 

我難倒就如何元組日期轉換爲datetime:那我有麻煩的代碼片段?

謝謝!

回答

1

行作爲列的元組返回,即使只有一列。

更改

for row in con.execute('select time_date as "d [datetime]" from fault_record'): 

for date, in con.execute('select time_date as "d [datetime]" from fault_record'): 

將迭代,而不是該行的元組在日期。