本文介绍了如何根据日期范围限制SQLite结果集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的class / SQLite表中有一个DateTime类型的列/类成员。 但是,这个查询都是:
I've got a column / class member of type DateTime in my class/SQLite table. However, both this query:
SELECT * FROM PhotraxBaseData WHERE dateTimeTaken >= '11/11/2009' AND dateTimeTaken <= '11/11/2014'-这一个:
-and this one:
SELECT * FROM PhotraxBaseData WHERE dateTimeTaken BETWEEN '11/11/2009' AND '11/11/2014'...不返回任何记录。这两个似乎都是语法接受的(它们运行没有错误),但在LINQPad中返回(0项),即使这些日期之间有多个记录。 我需要什么查询来获取正确的数据子集?
...return no records. Both of these seem to be accepted syntax-wise (they run without error), but return "(0 items)" in LINQPad, even though there are multiple records between those dates. What query do I need to get the correct subset of data?
推荐答案尝试以下 SELECT * FROM PhotraxBaseData WHERE dateTimeTaken BETWEEN CONVERT(DATETIME,'2009-11-11')AND CONVERT(DATETIME,'2014-11- 11'); 在您的示例中,您使用datetime变量检查字符串值,因此它可能无法给出正确的答案.. 在sql中使用Datetime Checking时,请考虑给定的日期格式是YYYY-mm - dd格式 - 它避免了对用户和SQL的混淆服务器系统... 对于Sql Lite: SELECT * FROM PhotraxBaseData WHERE dateTimeTaken BETWEEN'2009-11-11'AND'2014-11-1 1' SQL LITE不支持数据类型DATETIME。 但是在你的查询中你有将日期格式从'dd-mm-yyyy'更改为'yyyy-mm-dd' 这是SQL理解的标准日期格式。 请参阅以下有关SQL LITE数据类型的链接.. www.sqlite/datatype3.html [ ^ ]
尝试这样。 Try Like this. SELECT * FROM PhotraxBaseData WHERE strftime('%d/%m/%y', dateTimeTaken ) BETWEEN '11/11/2009' AND '11/11/2014'
我在声明中看不到任何错误,我检查样本模型及其工作正常... 我认为有时SQLite Datetime设置格式依赖于您的系统/笔记本电脑日期格式。 .. 请检查日期时间格式或者您可以将'11 / 11/2014'转换为Datetime对象,然后检查相同的条件... 谢谢, Ullas Krishnan Hi, I couldn't see any error in the statement, i checked with a sample model and its working fine... I think it may be sometime the SQLite Datetime settings format is keeping rely with your system/ laptop date format... Please check the Datetime format or you can convert the '11/11/2014' to Datetime object and then check the same condition... Thanks, Ullas Krishnan
更多推荐
如何根据日期范围限制SQLite结果集?
发布评论