Sql 获取日期区间

获取制定日期区间

declare @d as date
declare @d2 as date
set @d = '2014-06-03'
set @d2 ='2014-06-10'
select  convert(varchar(10),dateadd(dd,number,@d)) as dt
,dateadd(dd,-1,convert(varchar(8),dateadd(mm,1,@d),120)+'01')
from master..spt_values
where type='P' 
and dateadd(dd,number,@d)<=@d2 

获取制定月份所有日期

 declare @d as date
 set @d = '2014-06-01'
 select convert(varchar(10),dateadd(dd,number,convert(varchar(8),@d,120)+'01'),120) as dt
 from master..spt_values
 where type='P' 
 and dateadd(dd,number,convert(varchar(8),@d,120)+'01')<=dateadd(dd,-1,convert(varchar(8),dateadd(mm,1,@d),120)+'01')

 

posted @ 2014-11-07 13:20  jindahao  阅读(2071)  评论(0编辑  收藏  举报