简体   繁体   中英

get data from the last X minutes sqlite

I have this query:

SELECT who,whenAT
FROM seen
WHERE whenAT <= Datetime('now', '-5 minutes')

DateTimes stored in whenAT are formatted like this "10/12/2011 12:33:13 AM" whenAT is a TimeStamp.

that current query returns all records for some reason.

i'm inserting the datetime from code as DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") this is what is being saved into the table "10/12/2011 12:33:13 AM" i want to get all records within the last 5 minutes. everything i have tried either returns all records or no records.

as Fatal510 said, you need to add the modifier 'localtime'

here some reference about datetime modifier https://www.sqlite.org/lang_datefunc.html

and here some example

SELECT who,whenAT FROM seen WHERE whenAT >= Datetime('now', '-5 minutes', 'localtime')

Your query should be

SELECT who,whenAT FROM seen WHERE whenAT >= Datetime('now', '-5 minutes')

To get the last 5 minute, < will get everything besides the last 5 minutes

需要添加修饰符“ localtime”

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