Created
July 3, 2024 07:44
-
-
Save r1d3rzz/24b3a23810158bf7d826e94d834e716f to your computer and use it in GitHub Desktop.
Get Previous StartDate And EndDate
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 @CurrentDate DATE = GETDATE(); | |
DECLARE @FirstDayOfPreviousMonth DATE; | |
DECLARE @LastDayOfPreviousMonth DATE; | |
-- Calculate the first day of the previous month | |
SET @FirstDayOfPreviousMonth = DATEADD(MONTH, DATEDIFF(MONTH, 0, @CurrentDate) - 1, 0); | |
-- Calculate the last day of the previous month | |
SET @LastDayOfPreviousMonth = EOMONTH(DATEADD(MONTH, -1, @CurrentDate)); | |
-- Select the results | |
SELECT @FirstDayOfPreviousMonth AS StartDate, @LastDayOfPreviousMonth AS EndDate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment