简体   繁体   English

从最近X分钟获取数据

[英]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. 当AT是时间戳时,存储在whenAT中的DateTime的格式应为“ 2011年10月12日12:33:13 AM”。

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. 我从代码中将日期时间插入为DateTime.Now.ToString(“ yyyy-MM-dd HH:mm:ss”),这就是保存到表“ 10/12/2011 12:33:13 AM”中的内容我想在最近5分钟内获取所有记录。 everything i have tried either returns all records or no records. 我尝试过的一切都返回所有记录或没有记录。

as Fatal510 said, you need to add the modifier 'localtime' 如Fatal510所说,您需要添加修饰符“ localtime”

here some reference about datetime modifier https://www.sqlite.org/lang_datefunc.html 这里有关日期时间修饰符的一些参考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 要获得最后5分钟,<将获得除了最后5分钟之外的所有内容

需要添加修饰符“ localtime”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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