Friday, 13 May 2016

How to Get First Day and Last Day of a Current Quarter in SQL Server

To get the first day of the current quarter:

SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0)

To get the last day of the current quarter:

SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +1, 0))

To get the first day of the previous quarter

SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) - 1, 0)

To get the last day of the previous quarter:

SELECT DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0))

To get the first day of the next quarter:

SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) + 1, 0)

To get the last day of the next quarter:

SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +2, 0))




No comments:

Post a Comment