Snippets

Tessitura Network Community Last Business Day of Month

Created by Nick Reilingh last modified
DECLARE @datetime datetime = '4-30-2017';

SELECT
  last_business_day =
    DATEADD(
      day,
      -1 * ((ABS((DATEPART(weekday, DATEADD(month, DATEDIFF(month, 0, @datetime) + 1, 0)) + 4) % 7 - 4)
              + ((DATEPART(weekday, DATEADD(month, DATEDIFF(month, 0, @datetime) + 1, 0)) + 4) % 7 - 4)) / 2) - 1,
      DATEADD(month, DATEDIFF(month, 0, @datetime) + 1, 0)
    );

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.