C# Finisar SQLite 日期时间比较问题
我的“任务”数据库表如下所示:
[title] [content] [start_date] [end_date]
[...] [...] [01.06.2010 20:10:36] [06.06.2010 20:10:36]
[...] [...] [05.06.2010 20:10:36] [06.06.2010 20:10:36]
我只想查找那些满足给定日期在 start_date 和 end_date 之间的条件的记录。
我尝试了以下 SQL 表达式:
SELECT * FROM task WHERE
strftime ('%d', start_date) <= @day
AND
@day <= strftime ('%d', end_date)
其中 @day 是 SQLiteParameter (eq 5)。但没有返回结果。
我该如何解决这个问题?
谢谢。
My "task" database table look like this:
[title] [content] [start_date] [end_date]
[...] [...] [01.06.2010 20:10:36] [06.06.2010 20:10:36]
[...] [...] [05.06.2010 20:10:36] [06.06.2010 20:10:36]
And I want to find only those records that meet the condition that a given day is between start_date and end_date.
I've tried the following SQL expression:
SELECT * FROM task WHERE
strftime ('%d', start_date) <= @day
AND
@day <= strftime ('%d', end_date)
Where @day is an SQLiteParameter (eq 5). But no result is returned.
How can I solve this problem?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
似乎 SQLite3 中处理数据和时间的函数不接受像表列这样的参数。只需要字符串。但您可以使用字符串来比较数据。
示例:
这对我有用。
Seems that functions working with data and time in SQLite3 does not accept like parameter a table column. Expects only Strings. But instead you can make comparisons of data using strings.
Example:
This work for me.
您的列名称不应使用单引号,因为这会创建字符串。相反,您可以使用双引号,或者在这种情况下您根本不需要引号。试试这个:
或者也许你的意思是这样的:
Your column names shouldn't be in single quotes as that will create strings. Instead you can use double quotes, or in this case you don't need quotes at all. Try this instead:
or perhaps you mean this:
等等,误解了您想要的查询。这应该可行:
假设 @day 实际上是 2 位数字文本类型。要使其适用于数字类型,请使用:
Wait, misunderstood your intended query. This should work:
Provided @day is actually a 2 digit text type. For it to work with numeric types, use: