[MySql]查詢日期時間用法

文、意如

查詢日期區間

例:2023年7、8月資料

SELECT * FROM grade WHERE create_time >= '2023-07-01' AND create_time <= '2023-08-31';

SELECT * FROM grade WHERE create_time >= 20240501 AND create_time <= 20240630

使用介於BETWEEN

SELECT * FROM grade WHERE create_time BETWEEN '2023-07-01' AND '2023-08-31';

SELECT * FROM contact WHERE create_time BETWEEN 20240501 AND 20240630 AND del = 0


 

查詢加上時間

SELECT * FROM grade WHERE update_time >= '2023-07-01' AND update_time <= '2023-08-12 09:00:00';

 

Yiru@Studio - 關於我 - 意如