Menu Close

TSQL – How to Find Previous or Next Quarter Start and End Date

If you would like to find the start and the end of the previous Quarter based of a date here is the t-sql code you will need:

DECLARE @yourdate DATETIME = GETDATE();

SELECT DATEADD(qq, DATEDIFF(qq,0,@yourdate)-1, 0) AS [Previous_Quarter_Start]
, DATEADD(ms,-3,DATEADD(qq, DATEDIFF(qq,0,@yourdate), 0)) AS [Previous_Quarter_End_23_59]
, DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, @yourdate), 0)) AS [Previous_Quarter_End_00]

For next Quarter Start and End use this:

DECLARE @yourdate DATETIME = GETDATE();

SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) + 1, 0) AS [Next_Quarter_Start]
, DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +2, 0)) AS [Next_Quarter_End]

For getting the current Quarter start and end dates refer to this post:
https://mkncreations.com/site/2012/10/tsql-how-to-find-quarter-start-and-end-date/