做機房重構時,需要查詢某天的賬單,用“日期”為條件查詢該天的所有資料,那么應該如何獲取當天的時間段呢?
方法一:Between...and...
BETWEEN 運算子在 WHERE 子句中使用,作用是選取介于兩個值之間的資料范圍,
首先獲取兩個時間節點:
dtp1.Value = DateTime.Parse(DateTime.Now.Date.ToString() + " 00:00:00");
dtp2.Value = DateTime.Parse(DateTime.Now.Date.ToString() + " 23:59:59");
SQL陳述句:
select * from table1 where Date between 'dtp1' and 'dtp2'";
方法二:時間型別的模糊查詢,可以任意查詢某天
@date1 = date.ToString("yyyy-MM-dd")
select * from table1 where convert(varchar,Date,120) LIKE @date1+'%';
注:在使用時間型別的模糊查詢時,需要把時間的型別轉換為字串型別
以上內容為小編個人理解,如有問題歡迎在下方評論!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/247711.html
標籤:其他
上一篇:ORACLE中通過SQL陳述句(alter table)來增加、洗掉、修改欄位
下一篇:MySQL學習:資料庫的欄位屬性
