2003年7-8月:
select * from yourtabel where edate between '2003-07-01' and '2003-09-01'2000年-2001年:
select * from yourtabel where edate between '2000-01-01' and '2002-01-01'2003年7月5日至7月8日:
select * from yourtabel where edate between '2003-07-05' and '2003-07-09'
select * from yourtabel where edate between '2003-07-01' and '2003-09-01'2000年-2001年:
select * from yourtabel where edate between '2000-01-01' and '2002-01-01'2003年7月5日至7月8日:
select * from yourtabel where edate between '2003-07-05' and '2003-07-09'
select * from yourtabel where datepart(month,edate) between 7 and 82000年-2001年:
select * from yourtabel where datepart(year,edate) between 2000 and 2001
7月5日至7月8日:
select * from yourtabel where substring(convert(char(12),edate,120),6,5) between '07-05' and '07-08'
month(date字段) in(7,8)
right(convert(varchar(8),getdate(),112),3) between 705 and 708
2003年7-8月:
select * from yourtabel where edate >='2003-07-01' and edate <'2003-09-01'2000年-2001年:
select * from yourtabel where edate >='2000-01-01' and edate <'2002-01-01'2003年7月5日至7月8日:
select * from yourtabel where edate >='2003-07-05' and edate <'2003-07-09'
关键是掌握几个与日期相关的函数
DATEPART
返回代表指定日期的指定日期部分的整数。语法
DATEPART ( datepart , date ) 参数
datepart是指定应返回的日期部分的参数。下表列出了 Microsoft® SQL Server™ 识别的日期部分和缩写。日期部分 缩写
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
weekday dw
Hour hh
minute mi, n
second ss, s
millisecond ms
返回代表指定日期的天的日期部分的整数。语法
DAY ( date ) MONTH
返回代表指定日期月份的整数。语法
MONTH ( date )YEAR
返回表示指定日期中的年份的整数。语法
YEAR ( date )