Someone Help me Writing Date Script
Posted on 2009-04-09
I want to have startdate & enddate for 2009
Startdate should be Jan 31st 2009
EndDate should be March 31st 2009(Since Last Accounting Month is March)
Since, i need to use these dates in While Loop to run Temp Table.
Since for Every month end I need to run Procedure. So, i need to insert the code for StartDate & EndDate
I already wrote Below Code, but it doesnt work for March...The code is taking March 28th instead of March 31st, Since, Feb Month runs for 28th.
Declare @StartDate datetime
Declare @EndDate datetime
Set @EndDate = CONVERT(varchar,DATEADD(d,-DAY(GetDate()),GetDate()),101)
Set @StartDate = '1/31/'+ CAST(YEAR(@EndDate)as Char(4))
While @StartDate <= @EndDate
--Inserting Data into table
set @StartDate = dateadd(m, 1, @StartDate)