在python中比较日期



我正在尝试在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()

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

相关内容

  • 没有找到相关文章

最新更新