Get First Day of the Quarter

Get First Day of the Quarter

I’m building a Stored Procedure and Report that needs to limit to data created in the previous quarter, only. The assumption is the report will be run on the first day of a new quarter, but could be run any time within the current quarter.

Can be achieved like so:

DECLARE @startDate DATETIME, @endDate DATETIME
SELECT 
 @startDate = DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) - 1, 0),
 @endDate = DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0))
Mike250

I'm an Australian Chief Analytics Officer passionate about data science, visual insights, and all things sport—particularly cricket. An adventurer at heart, I’ve gone from abseiling cliffs to snorkeling in crystal-clear waters, sleeping in the wilds of Africa, and exploring destinations worldwide, with my latest trip taking me to Bali. When I'm not diving into data or analytics, I'm spending time with my three sons and two daughters, attempting to hit sixes for my local cricket club, reviewing chicken schnitzels or honing my craft around a coffee machine.

Related Posts
Leave a comment

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