1.如果查詢日期參數為'2017/02/21',而數據庫表中的字段為'2017/02/21 12:34:16.963',則需要格式化一下日期才能查詢出來,如下
select * from table t where t.date between CONVERT(datetime, '2017/02/21', 120) and CONVERT(datetime, '2017/02/21', 120)+' 23:59:59') ;
查詢的范圍為'2017/02/21 00:00:00'~'2017/02/21 23:59:59',這樣就能解決問題。
2.或者使用dateadd方法,把日期加1天,如下
select * from table t where t.date >= CONVERT(datetime, '2017/02/21') and t.date < CONVERT(datetime, dateadd(day,1,'2017/02/21'));
查詢的范圍為'2017/02/21' <= t.date < '2017/02/22',這樣也能解決問題。
