The script calculates the end and the beginning of the last, the current and the next months.
2007-10-02 (first published: 2002-06-20)
15,449 reads
The script calculates the end and the beginning of the last, the current and the next months.
DECLARE @Today smalldatetime DECLARE @FirstOfMonth smalldatetime DECLARE @Year varchar(4), @Month varchar(2) SELECT @Today = GetDate() SELECT @Year = CONVERT(varchar(4), DATEPART(yy, @Today)) SELECT @Month = CONVERT(varchar(2), DATEPART(mm, @Today)) SELECT @FirstOfMonth = CONVERT(smalldatetime, @Year + '-' + @Month + '-' + '1') SELECT 'End Of the Last Month', DATEADD(dd, -1, @FirstOfMonth) SELECT 'End Of the Current Month', DATEADD(dd, -1, DATEADD(mm, +1, @FirstOfMonth)) SELECT 'End Of the Next Month', DATEADD(dd, -1, DATEADD(mm, +2, @FirstOfMonth)) SELECT 'Beginning Of the Last Month', DATEADD(mm, -1, @FirstOfMonth) SELECT 'Beginning Of the Current Month', @FirstOfMonth SELECT 'Beginning Of the Next Month', DATEADD(mm, +1, @FirstOfMonth)