MySQL日期范围查询
文章描述:
mysql对数据进行日期查询已经时间戳转换查询
between and
使用between and对日期进行查询,查询条件开始时间与结束时间
SELECT * FROM `user` WHERE datatime between '2019-01-01 00:00:00' and '2019-12-31 23:59:59'
大于等于和小于等于
SELECT * FROM `user` WHERE datatime >= '2019-01-01 00:00:00' AND datatime <= '2019-12-31 23:59:59'
UNIX_TIMESTAMP
这里把时间转换为UNIX_TIMESTAMP比较,datetime若加了索引,不走索引
SELECT * FROM `user` where UNIX_TIMESTAMP(datatime) between UNIX_TIMESTAMP('2019-01-01 00:00:00') and UNIX_TIMESTAMP('2019-12-31 23:59:59')
发布时间:2021/07/28
发表评论