python - 比较python中的日期

标签 python postgresql python-2.7 datetime psycopg2

<分区>

我正在尝试比较 python 中的日期。谁能告诉我为什么这行不通。

 cursor = conn.cursor()

 tech = raw_input("Please enter your id number: ")

 cursor.execute("Select cust_id from client where tech_id = %s" % tech)
 rows = cursor.fetchall()
 day_num = datetime.datetime.today().weekday()


 dte = datetime.datetime.today()
 week = datetime.timedelta(days=5)
 service_inc = datetime.timedelta(days=14)
 friday = dte + datetime.timedelta(days=5)
 work = []
 for row in rows:
     client = row[0];
     cursor.execute("Select last_serviced from client where " \
     "cust_id= %s" % client)
     ser_date = cursor.fetchone()
     ser_date = ser_date[0] + service_inc
     if dte <= ser_date <= friday:
         work.append(client)

我不断收到的错误是无法将 datetime.datetime 与 datetime.date 进行比较。提前感谢您的帮助。

最佳答案

看起来像是类型错误。

ser_date = cursor.fetchone()

以上需要设置为日期类型进行比较。

关于python - 比较python中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38622876/

相关文章:

Python程序卡住计算机

python - 在 TF 2.0 上设置随机种子

python-2.7 - 我的 if-else 循环只运行三次,而它应该运行更多次

python - 为 Pandas 中的多列赋值

python - 获取基于特定项目的先前值

iphone - web2py可以支持RESTful api调用吗?如果有的话,有关于如何构建一个的指导吗?我

python - 没有 Akismet 的垃圾邮件过滤表单

PostgreSQL now() 值不改变函数中的值

sql - 在 postgres 中调整子查询

ruby-on-rails - 您要查找的页面不存在 - heroku+rails