小于日期不会选择相等的日期sql。

时间:2022-09-18 13:00:35

The where clause which I have:

我的where子句:

r.completed <= '2017-01-12'

The r.completed (datetime) values are formatted as for example:

r完成(datetime)值的格式为:

2017-01-06 14:48:29

This where clause doesn't select instances that are equal to the date given. How could I fix this problem? I have tried convert(datetime, '2017-01-12') but this gives an SQL error. DBMS is MySQL.

这个where子句不选择与给定日期相等的实例。我怎么解决这个问题?我尝试过转换(datetime, '2017-01-12'),但这给出了一个SQL错误。DBMS是MySQL。

3 个解决方案

#1


1  

In MySQL, you can use

在MySQL中,可以使用。

CAST(r.completed as DATE) <='2017-01-12'

#2


3  

The date 2017-01-12 is translated to 2017-01-12 00:00:00

日期:2017-01-12被翻译成2017-01-12 00:00:00。

So a value like 2017-01-12 14:48:29 is greater than 2017-01-12 00:00:00.

因此,像2017-01-12 14:48:29这样的值大于2017-01-12 00:00。

If you want to match also this particular day you would have to use r.completed < '2017-01-13'

如果你想在这个特殊的日子里比赛,你必须使用r完成的< '2017-01-13'

#3


0  

Try this if you want to inlcude all time of the given date

如果你想在给定的时间内输入所有的时间,试试这个。

r.completed < '2017-01-13'

The above will include all date before start of 2017-01-13

以上内容将包括在2017-01-13开始之前的所有日期。

#1


1  

In MySQL, you can use

在MySQL中,可以使用。

CAST(r.completed as DATE) <='2017-01-12'

#2


3  

The date 2017-01-12 is translated to 2017-01-12 00:00:00

日期:2017-01-12被翻译成2017-01-12 00:00:00。

So a value like 2017-01-12 14:48:29 is greater than 2017-01-12 00:00:00.

因此,像2017-01-12 14:48:29这样的值大于2017-01-12 00:00。

If you want to match also this particular day you would have to use r.completed < '2017-01-13'

如果你想在这个特殊的日子里比赛,你必须使用r完成的< '2017-01-13'

#3


0  

Try this if you want to inlcude all time of the given date

如果你想在给定的时间内输入所有的时间,试试这个。

r.completed < '2017-01-13'

The above will include all date before start of 2017-01-13

以上内容将包括在2017-01-13开始之前的所有日期。