17

是否有可能获得 Sqlite3 中两个 TIMESTAMP 值之间的差异(以秒为单位)?

例如,我尝试了以下查询:

SELECT CURRENT_TIMESTAMP - my_timestamp FROM my_table;

我总是得到'0'。谁能告诉我我做错了什么?(注意,我已经验证 my_timestamp 确实是过去的。)

4

2 回答 2

17

Got it:

SELECT (julianday(CURRENT_TIMESTAMP) - julianday(my_timestamp)) * 86400.0) FROM my_table;

julianday returns the fractional number of days since noon in Greenwich on November 24, 4714 B.C. I then take the difference and multiply by the number of seconds per day.

于 2013-07-17T19:11:35.203 回答
10

最接近秒的另一种变体

CAST(strftime('%s', CURRENT_TIMESTAMP) as integer) - 
CAST(strftime('%s', my_timestamp) as integer)
于 2014-12-29T17:31:06.107 回答