Skip to content

Instantly share code, notes, and snippets.

@kwestground
Created November 30, 2016 13:24
Show Gist options
  • Save kwestground/753fa0ebe0a03f1f93cb88b8693485d9 to your computer and use it in GitHub Desktop.
Save kwestground/753fa0ebe0a03f1f93cb88b8693485d9 to your computer and use it in GitHub Desktop.
DECLARE @Now date = GETDATE()
SELECT
@Now AS [Today],
DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)-0, 0) AS [Current_From],
DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)+1,0)) AS [Current_To],
DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)-1, 0) AS [LastMonth_From],
DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)+0,0)) AS [LastMonth_To],
DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)-2, 0) AS [LastMonth2_From],
DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)-1,0)) AS [LastMonth2_To],
DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)-12, 0) AS [LastYearMonth_From],
DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH,0,@Now)-12,0)) AS [LastYearMonth_To]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment