前端傳入的引數確是 yyyy-mm-dd 的 沒有帶時分秒。
如果按照下面這兩種方式會查不全
select * from test where create_time between '2018-07-30' and '2018-07-31'
;select * from test where create_time >=
'2018-07-30' and date <=
'2018-07-31'
;
我這裡提供兩種方式:
第一種: 讓前端傳固定的格式 yyyy-mm-dd hh:mm:ss 繼續用上面的方法。
第二種:你用mysql的函式date_format
select * from test where date_format
(create_time,
'%y-%m-%d'
) between '2018-07-30' and '2018-07-31'
;
這樣就能得到你全部在區間內的資料了。 Mysql查詢時間範圍
sql 今天 select from 表名 where to days 時間欄位名 to days now 昨天 select from 表名 where to days now to days 時間欄位名 1 近7天 select from 表名 where date sub curdate in...
mysql 查詢時間轉換 Mysql 查詢時間轉換
利用data format函式 select date format now y m d 根據format字串格式化date值 s,s 兩位數字形式的秒 00,01,59 i,i 兩位數字形式的分 00,01,59 h 兩位數字形式的小時,24 小時 00,01,23 h 兩位數字形式的小時,12 ...
查詢時間範圍與YEARWEEK用法
目錄 1 根據時間範圍查詢語句 2 yearweek 今天 select from 表名 where to days 時間欄位名 to days now 昨天 select from 表名 where to days now to days 時間欄位名 1 近7天 select from 表名 wh...