我正在尝试比较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进行比较。感谢您提前提供任何帮助。
答案 0 :(得分:-1)
它看起来像是一个类型错误。
ser_date = cursor.fetchone()
以上内容需要设置为日期类型进行比较。