SQLServer : Get Last Businessday of previous month

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

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.