1. 日期比較
select * from table_name where date(start_time) between '2022-03-21' and '2022-03-22'
2. 時間比較
SELECT * FROM table_name WHERE start_time <= '2022-03-22 00:00:00' and start_time >= '2022-03-21 00:00:00'
`start_time` datetime NOT NULL COMMENT '開始時間',
mysql version: 8.0.18
時間查詢限制
查詢前兩天的數據
SELECT * FROM table_name where start_time >= now()-interval 2 day
查詢5個月之前的數據(例2023-06-12 推到 2023-01-12)
select * from table_name where create_time > DATE_SUB(CURDATE(), INTERVAL 5 MONTH)
查詢5個月之前的數據 推月份(例2023-06-12 推到 2023-01-01)
select * from table_name where create_time > DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 5 MONTH), '%Y-%m-01')
