Monday, March 26, 2012

Find out Month start date and end date

declare @date datetime='2012-03-26 18:25:59.620'

Declare @month int,@year int,@startdate datetime,@enddate datetime,@vdate datetime,@count int

select @month=MONTH(@date),@year=YEAR(@date)

select @startdate=cast(@year as varchar)+'-'+cast(@month as varchar)+'-'+'01'

select @vdate=DATEADD(mm,1,@startdate)

select @count=DATEDIFF(DAY,@startdate,@vdate)

select @enddate=DATEADD(day,@count-1,@startdate)

select @startdate as startdate,@enddate  as enddate,datename(DW,@startdate) as startdatename,datename(dw,@enddate) as enddatename


No comments:

Post a Comment