Created
November 30, 2016 13:24
-
-
Save kwestground/753fa0ebe0a03f1f93cb88b8693485d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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