2
我想比較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進行比較。感謝您提前提供任何幫助。
因爲您試圖將日期與時間進行比較。那天的日期應該是什麼日期?要麼給日期添加時間,要麼從日期時間中刪除它,*然後*進行比較。 – jonrsharpe
http://stackoverflow.com/questions/7239315/cant-compare-datetime-datetime-to-datetime-date – user2853437