Skip to content

Instantly share code, notes, and snippets.

@afreeland
Last active May 23, 2016 15:38
Show Gist options
  • Save afreeland/4eb18990d784c87bd3379642999d72c1 to your computer and use it in GitHub Desktop.
Save afreeland/4eb18990d784c87bd3379642999d72c1 to your computer and use it in GitHub Desktop.
SQL: Month name from number
-- Renders out May
Select DateName(month, DateAdd(month, 5, -1))
-- https://msdn.microsoft.com/en-us/library/ms174395.aspx
-- DateName(datepart, date)
-- https://msdn.microsoft.com/en-us/library/ms186819.aspx
-- DateAdd(datepart, number, date)
-- @datepart - the particular part of the date (year, month, etc.,) that will be incremented by an integer
-- @number - the month we are targeting
-- @date - An integer that will return back a particular date
-- @example
-- select DateAdd(month, 5, 0) -1
-- select DateAdd(month, 5, -1)
-- ** both return 1900-05-31 00:00:00.000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment