开发者

get data from the last X minutes sqlite

开发者 https://www.devze.com 2023-04-12 05:14 出处:网络
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 TimeSta

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.


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


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')


needed to add the modifier 'localtime'

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号