SELECT *
FROM `summary`
WHERE submit_date = curdate()
AND submit_date > '06:00'
AND submit_date < '21:00'
LIMIT 0 , 30
这是取消包括今天在内的所有日期?submit_date 是一个显示有 DATETIME 的列,它没有像应有的那样过滤掉它们。我错过了什么?谢谢!
您的 2 个限制条件应与列返回的值进行比较TIME()
,DATETIME
第一个条件应仅限于该DATE()
部分。
SELECT *
FROM `summary`
WHERE
/* Truncate to the date only to compare against CURDATE() */
DATE(submit_date) = curdate()
/* And truncate to the TIME() to compare against these time literals. */
/* note also that the time literals may need seconds as well */
AND TIME(submit_date) > '06:00:00'
AND TIME(submit_date) < '21:00:00'
LIMIT 0 , 30
您应该只比较 submit_date 的日期部分与当前日期的日期部分,然后是小时部分,如下所示:
SELECT *
FROM `summary`
WHERE
DATE(submit_date) = curdate()
AND HOUR(submit_date( BETWEEN 6 AND 21
LIMIT 0 , 30