有个字段created_at
是 datetime 类型,如何选择当天日期的数据?
SELECT * FROM data WHERE created_at = '2017-06-29';
SELECT * FROM data WHERE created_at BETWEEN '2017-06-29 00:00:00' AND '2017-06-29 23:59:59';
都不对,结果集都是空的
1
revotu 2017-06-29 09:57:30 +08:00
MySQL 时间处理相关函数 : http://www.revotu.com/mysql-date-and-time-functions.html
WHERE DATE(created_at) = '2017-06-29' 或是 WHERE created_at LIKE '2017-06-29%' |
2
mkeith 2017-06-29 21:18:50 +08:00
是不是 between 不包含边界啊?你换成大于等于看看,楼上方法没法走索引吧
|