A better version of the :
"Finding first/last day of month by a date"
2007-10-02 (first published: 2002-06-20)
15,451 reads
A better version of the :
"Finding first/last day of month by a date"
DECLARE @SomeDate DATETIME SELECT@SomeDate = GETDATE() SELECTCONVERT(datetime, CONVERT(VARCHAR(6), DATEADD(MONTH, -1, @SomeDate), 112) + '01', 112) as FirstDayPrevMonth, CONVERT(datetime, CONVERT(VARCHAR(6), @SomeDate, 112) + '01', 112) as FirstDayThisMonth, CONVERT(datetime, CONVERT(VARCHAR(6), DATEADD(MONTH, +1, @SomeDate), 112) + '01', 112) as FirstDayNextMonth, CONVERT(datetime, CONVERT(VARCHAR(6), @SomeDate, 112) + '01', 112) - 1 as LastDayPrevMonth, CONVERT(datetime, CONVERT(VARCHAR(6), DATEADD(MONTH, +1, @SomeDate), 112) + '01', 112) - 1 as LastDayThisMonth, CONVERT(datetime, CONVERT(VARCHAR(6), DATEADD(MONTH, +2, @SomeDate), 112) + '01', 112) - 1 as LastDayNextMonth