MySQL中查询datetime类型的字段时,直接使用时间字符串和比较运算符即可。
SELECT * from orders WHERE create_at >= '2021-01-01';
SELECT * from orders WHERE created_at >= '2021-01-01 00:00:00' AND created_at <= '2021-01-31 23:59:59';
SELECT * from orders WHERE create_at >= '2021-01-01' AND created_at < '2021-02-01';
查询范围也可以使用 between 运算符:
SELECT * from od WHERE create_time between '2021-01-01 00:00:00' and '2021-01-01 23:59:59';