SQL中查詢日期語句
SQL SERVER:
用函數datepart處理就可以了,示例:
select datepart(weekday,getdate()) as 周內的第幾日
select datepart(week,getdate()) as 年內的第幾周
select datepart(quarter,getdate()) as 年內的第幾季
周內的第幾日
-----------
5
(所影響的行數為 1 行)
年內的第幾周
-----------
34
(所影響的行數為 1 行)
年內的第幾季
-----------
3
(所影響的行數為 1 行)
SQL查詢時間范圍語句
以下為MS_SQL的寫法分日期和小時條件;
select *
from xy
where
(id=27 or id=28)and convert(varchar(10),WRITETIME,120) between '2009-01-26' and '2009-02-06'
and
convert(varchar(8),WRITETIME,108) between '08:00:00'and '12:30:00'