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

To get the first day of the previous quarter in SQL Server, use the following code:

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

first_day_of_last_quarter

To get the last day of the previous quarter:

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

last_day_of_last_quarter

To get the first day of the current quarter:

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

first_day_of_current_quarter

To get the last day of the current quarter:

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

last_day_of_current_quarter

To get the first day of the next quarter:

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

first_day_of_next_quarter

To get the last day of the next quarter:

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

last_day_of_next_quarter