【问题标题】:[TypeError: can't compare datetime.datetime to tuple]: How to compare a tuple value to a datetime value using Python & SQLite3?[TypeError: can't compare datetime.datetime to tuple]: 如何使用 Python & SQLite3 将元组值与日期时间值进行比较?
【发布时间】:2012-02-28 01:02:03
【问题描述】:

我在 Python 中使用 SQLite3 模块,我目前有一个将“日期”存储为日期时间的表。但是,每当我尝试从表中检索该日期并将其与今天的日期进行比较(例如,今天 = datetime.datetime.today())时,我都会收到一条错误消息:

if row > today:

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

这是我遇到问题的代码的 sn-p:

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

if row < today:
    print row

我对如何将元组日期转换为日期时间感到困惑?

谢谢!

【问题讨论】:

    标签: python sqlite


    【解决方案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'):
    

    将迭代日期,而不是行元组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多