Get first & last day of the month

Get first & last day of the month

I’m building a Stored Procedure and Report that sets the default start date as the first day of the month one (1) month ago. Can easily be adapted to this month, twelve (12) months ago, etc.

Can be achieved like so:

-- First day of prev month
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) 

-- Lastday of prev month
SELECT DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1) 
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(-1)
=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)
Mike250

Australian. Sport. Passionate Cricket Fan. Go Pro. Abseiling. Snorkeling. Travel. Golf R. SQL Server Developer. Three sons. One daughter. Last Trip: New York.

Related Posts
Leave a comment

Your email address will not be published. Required fields are marked *