C# Finisar SQLite 日期时间比较问题

发布于 2024-09-03 17:37:51 字数 494 浏览 5 评论 0原文

我的“任务”数据库表如下所示:

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅笑轻吟梦一曲 2024-09-10 17:37:51
SELECT *
FROM task
WHERE @day BETWEEN date(start_date) and date(end_date)
SELECT *
FROM task
WHERE @day BETWEEN date(start_date) and date(end_date)
永言不败 2024-09-10 17:37:51

似乎 SQLite3 中处理数据和时间的函数不接受像表列这样的参数。只需要字符串。但您可以使用字符串来比较数据。

示例:

SELECT * FROM table WHERE
table_column> = "06.25.2010 00:00:00"
AND
table_column <"06.25.2010 23:59:59"

这对我有用。

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:

SELECT * FROM table WHERE
table_column> = "06.25.2010 00:00:00"
AND
table_column <"06.25.2010 23:59:59"

This work for me.

地狱即天堂 2024-09-10 17:37:51

您的列名称不应使用单引号,因为这会创建字符串。相反,您可以使用双引号,或者在这种情况下您根本不需要引号。试试这个:

SELECT *
FROM task
WHERE strftime('%d', start_date) <= @day
AND @day <= strftime('%d', end_date)

或者也许你的意思是这样的:

SELECT *
FROM task
WHERE date(start_date) <= @day
AND @day <= date(end_date)

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:

SELECT *
FROM task
WHERE strftime('%d', start_date) <= @day
AND @day <= strftime('%d', end_date)

or perhaps you mean this:

SELECT *
FROM task
WHERE date(start_date) <= @day
AND @day <= date(end_date)
时光是把杀猪刀 2024-09-10 17:37:51

等等,误解了您想要的查询。这应该可行:

SELECT * FROM task WHERE
strftime ('%d', start_date) <= @day
AND
@day <= strftime ('%d', end_date)

假设 @day 实际上是 2 位数字文本类型。要使其适用于数字类型,请使用:

SELECT * FROM task WHERE
CAST(strftime('%d', start_date) as integer) <= @day
AND
@day <= CAST(strftime('%d', end_date) as integer)

Wait, misunderstood your intended query. This should work:

SELECT * FROM task WHERE
strftime ('%d', start_date) <= @day
AND
@day <= strftime ('%d', end_date)

Provided @day is actually a 2 digit text type. For it to work with numeric types, use:

SELECT * FROM task WHERE
CAST(strftime('%d', start_date) as integer) <= @day
AND
@day <= CAST(strftime('%d', end_date) as integer)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文