Search code examples
sqlsql-servert-sqlsql-server-2016date-arithmetic

SQL: Get Friday of Second Full Week of Month


Here's an interesting equation of sorts. I'm looking for the cleanest way to retrieve the second full-week Fridays of each month for any given year. Assuming the week begins on Monday.

EXAMPLES

  • November 2017 would be the 17th.
  • December 2017 would be the 15th.
  • January 2018 would be the 12th.

These things are fun usually but I'm not feeling it right now. Any suggestions?


Solution

  • This might be not easy to understand at first, but for this specific case rules are simple:

    weekday = 'Friday' (or whichever way to determine if this day is Friday)
    and day_of_month between 12 and 18
    

    This will work if week starts on Monday.