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

If the post helped you, please share it:
Pin It

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">