【发布时间】:2020-12-22 04:50:37
【问题描述】:
我有这段代码不工作...
currentTime = dt.utcnow().date() get just the day has to be UTC cause that what stored in db.
print(currentTime) #shows day of 2020-09-03
cur = conn.cursor()
cur.execute("SELECT f.user_id, u.first_name, f.location, f.checkin, f.checkout FROM auth_user u JOIN covidlog_onsitelog as f ON (f.user_id=u.id) WHERE CAST(f.checkin as 'DATE()') = ? or CAST(f.checkout as 'DATE()') =?", (currentTime,currentTime))
该字段是在 django 中作为模型创建的,其中包含以下项目:
2020-09-03 00:40:58.901602
但我只想比较 DAY 而不管时间...虽然它似乎不起作用。
所以对我来说这看起来是正确的,但没有产生结果,所以我只能假设它仍然以某种方式将日期与时间戳进行比较......知道如何不这样做并从字面上与日期进行比较吗?
【问题讨论】:
标签: sql python-3.x sqlite datetime where-clause