Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare @Date1 date,
- @Date2 date;
- Set @Date1 = '4/11/2015';
- Set @Date2 = getdate();
- With Months
- As (Select Month(@Date1) As TheMonth,
- Year(@Date1) As TheYear,
- @Date1 As TheDate
- Union All
- Select Month(DateAdd(month, 1, TheDate)) As TheMonth,
- Year(DateAdd(month, 1, TheDate)) As TheYear,
- DateAdd(month, 1, TheDate) As TheDate
- From Months
- Where TheDate < @Date2)
- Select TheMonth, TheYear,
- TheDays = DateDiff(day, EOMONTH(TheDate, -1), EOMONTH(TheDate))
- From Months;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement