[英]Less than date doesn't select equal date sql
The where clause which I have: 我有where子句:
r.completed <= '2017-01-12'
The r.completed (datetime) values are formatted as for example: r.completed(日期时间)值的格式如下:
2017-01-06 14:48:29
This where clause doesn't select instances that are equal to the date given. 此where子句不会选择等于给定日期的实例。 How could I fix this problem? 我该如何解决这个问题? I have tried convert(datetime, '2017-01-12') but this gives an SQL error. 我尝试了convert(datetime,'2017-01-12'),但这给出了SQL错误。 DBMS is MySQL. DBMS是MySQL。
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:00
。
If you want to match also this particular day you would have to use r.completed < '2017-01-13'
如果您想在这一天也进行比赛,则必须使用r.completed < '2017-01-13'
在MySQL中,您可以使用
CAST(r.completed as DATE) <='2017-01-12'
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年1月13日开始之前的所有日期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.