简体   繁体   中英

Less than date doesn't select equal date sql

The where clause which I have:

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

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

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.

The date 2017-01-12 is translated to 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 .

If you want to match also this particular day you would have to use 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM