Testing

0

Please login or register to vote for this query.

(click on this box to dismiss)

Gardening and Landscaping

Q&A for gardeners and landscapers

DECLARE @STARTDATE DATETIME = '2008-01-01'
DECLARE @UNTILDATE DATETIME = '2018-12-31'
DECLARE @HOWMANYMONTH INT = 2
DECLARE @ENDDATE DATETIME 
SET @ENDDATE = DATEADD(month, ((YEAR(DATEADD(Month, @HOWMANYMONTH, @STARTDATE)) - 1900) * 12) + MONTH(DATEADD(Month, @HOWMANYMONTH, @STARTDATE)), -1)

WHILE @ENDDATE <= @UNTILDATE
BEGIN
   
   PRINT CAST(@STARTDATE AS VARCHAR(50)) +'  ' +  CAST(@ENDDATE  AS VARCHAR(50))
   SET @STARTDATE = DATEADD(day,1, @ENDDATE)
   SET @ENDDATE =  DATEADD(month, ((YEAR(DATEADD(Month, @HOWMANYMONTH, @STARTDATE)) - 1900) * 12) + MONTH(DATEADD(Month, @HOWMANYMONTH, @STARTDATE)), -1)
       
END

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results