如何根据日期范围限制SQLite结果集?

编程入门 行业动态 更新时间:2024-10-14 20:23:01
本文介绍了如何根据日期范围限制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结果集?

本文发布于:2023-11-22 01:54:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   SQLite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!