Sql 获取日期区间

时间:2025-01-16 13:07:02

获取制定日期区间

declare @d as date
declare @d2 as date
set @d = '2014-06-03'
set @d2 ='2014-06-10'
select convert(varchar(),dateadd(dd,number,@d)) as dt
,dateadd(dd,-,convert(varchar(),dateadd(mm,,@d),)+'')
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(),dateadd(dd,number,convert(varchar(),@d,)+''),) as dt
from master..spt_values
where type='P'
and dateadd(dd,number,convert(varchar(),@d,)+'')<=dateadd(dd,-,convert(varchar(),dateadd(mm,,@d),)+'')