List of months between date range
DECLARE @DateStart DATETIME = '2013-07-01' -- 2013 July
DECLARE @DateEnd DATETIME = '2015-03-11'; -- 2015 March
select year(dates) as Year,month(dates) as MontNumber,
left(convert(char(10),dates,101),2) as MonthNumberLeadingZero,
datename(month,dates) as MonthName
from
(
select dateadd(month,number,@DateStart) as dates from master..spt_values
where type='p' and number between 0 and datediff(month,@DateStart,@DateEnd)
) as t
DECLARE @DateStart DATETIME = '2013-07-01' -- 2013 July
DECLARE @DateEnd DATETIME = '2015-03-11'; -- 2015 March
select year(dates) as Year,month(dates) as MontNumber,
left(convert(char(10),dates,101),2) as MonthNumberLeadingZero,
datename(month,dates) as MonthName
from
(
select dateadd(month,number,@DateStart) as dates from master..spt_values
where type='p' and number between 0 and datediff(month,@DateStart,@DateEnd)
) as t
No comments:
Post a Comment