Skip to content

Instantly share code, notes, and snippets.

@renatocfrancisco
Last active January 13, 2023 14:58
Show Gist options
  • Save renatocfrancisco/27e5fcbe3c95b69e27adf460a5addb15 to your computer and use it in GitHub Desktop.
Save renatocfrancisco/27e5fcbe3c95b69e27adf460a5addb15 to your computer and use it in GitHub Desktop.
Weekly and Monthly Dates in SQL
-- 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