Last active
January 13, 2023 14:58
-
-
Save renatocfrancisco/27e5fcbe3c95b69e27adf460a5addb15 to your computer and use it in GitHub Desktop.
Weekly and Monthly Dates in SQL
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
-- Weekly | |
-- first day of week, in this case, monday | |
DATEADD(DAY, 2 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE)); | |
-- last day of week, in this case, sunday | |
DATEADD(DAY, 8 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE)); | |
-- Monthly | |
-- first day of month | |
DATEADD(D,1,EOMONTH(GETDATE(),-1)); | |
-- last day of month | |
EOMONTH(GETDATE()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment