1 回答

TA貢獻1802條經驗 獲得超6個贊
我發現了問題(嗯,實際上是一個同事),它就在這里:
第一個元素:'end':'2019-10-24T00:00:00.000Z'||'start':'2019-10-23T00:00:00.000Z'
其他元素:'end': '2019-10-23T00:00:00.00.000Z'||'start': '2019-10-21T00:00:00.00.000Z'
事情是:2019-10-24T 00:00:00 .000Z 和 2019-10-23T 00:00:00.00 .000Z
我使用這個 SQL 來比較日期(它們沒有存儲在 ISO 8601 中):
SELECT id, ....., strftime('%Y-%m-%dT%H:%M:%fZ', start_date) AS start, strftime('%Y-%m-%dT%H:%M:%fZ', end_date) AS end, ......
FROM table
WHERE state = 'Active' AND start > '....' AND end < '....'
我的問題是假設SQlite strftime它等于PYTHON strftime,但不是。
我使用的是這個(Python):'%Y-%m-%dT%H:%M: %S.%f Z'而不是這個(SQlite):'%Y-%m-%dT%H:% M: %f Z'
Python 文檔
%S Second as a zero-padded decimal number.
%f Microsecond as a decimal number, zero-padded on the left.
Sqlite 文檔
%S seconds: 00-59
%f fractional seconds: SS.SSS
所以要小心,不要將 python 格式與 sqlite 格式混淆。
添加回答
舉報