简体   繁体   中英

Sqlite Timestamp various compare

How is it possible to compare a TIMESTAMP column by date or time?

I try to retrieve records that difference of TIMESTAMP column and NOW are a week or 2 hours or less 30 minutes.

SELECT FROM Tcase WHERE (date_time-datetime('now'))<7day
SELECT FROM Tcase WHERE (date_time-datetime('now'))<1hour

Example

SELECT * FROM Tcase
WHERE datetime(date_time,'-7 day', '+5 hour', '+10 minute') >= date('now')

Edit

SELECT * FROM Tcase
date('now') > datetime(date_time,'+7 day')
OR date('now') < datetime(date_time,'-7 day') 

See SQLite date functions

SQLFiddle example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM