Difference in seconds between timestamps in Sqlite3

前端 未结 2 1410
[愿得一人]
[愿得一人] 2020-12-06 05:51

Is it possible to get the difference (in seconds) between two TIMESTAMP values in Sqlite3?

For instance, I\'ve tried the following query:

SELECT CUR         


        
相关标签:
2条回答
  • 2020-12-06 06:24

    Another variant to the nearest second

    CAST(strftime('%s', CURRENT_TIMESTAMP) as integer) - 
    CAST(strftime('%s', my_timestamp) as integer)
    
    0 讨论(0)
  • 2020-12-06 06:34

    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.

    0 讨论(0)
提交回复
热议问题