Homefeatured

SQLServer : Get Last Businessday of previous month

Like Tweet Pin it Share Share Email

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

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *