Script(s)

technology as-is

SQLServer : Get Last Businessday of previous month

| 0 comments

DECLARE @LastmonLastBusinessDay date, @inputdate date

SET @inputdate = ’05/25/2014′

SELECT @LastmonLastBusinessDay = DATEADD(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@inputdate),0))
– CASE DATENAME(dw,DATEADD(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@inputdate),0)))
WHEN ‘SUNDAY’ THEN 2
WHEN ‘SATURDAY’ THEN 1
ELSE 0
END
print @LastmonLastBusinessDay

Leave a Reply

Required fields are marked *.