Find First and Last Day of the Current Quarter in SQL Server

I was recently working on a requirement where the user wanted a report with data from the First day to the Last Day of the current Quarter

Here's a simple way to find the Find First and Last Day of the current quarter in SQL Server 2005/2008

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

SELECT DATEADD(qq,DATEDIFF(qq,-1,GETDATE()),-1) as LastDayOfQuarter


FirstDayOfQuarter         LastDayOfQuarter

2009-04-01 00:00:00.000   2009-06-30 00:00:00.000

About The Author

Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and a new one recently at The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigous Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.

Get in touch with him on Twitter @suprotimagarwal, LinkedIn or befriend him on Facebook


darksander said...

Thanks a lot for your gem :)

Serginho said...

Thank you very much, also it works for first day of the month, quarter and year.

It's really a gem.

Anonymous said...

Thats great - any ideas how to do this in the code of ssrs i.e. in c#?

Thanks :)

Anonymous said...

Thanks..its working..
But i didn't get d logic..

If possible plz Mention d logic

......MAster ANil

shalala said...
This comment has been removed by the author.
Anonymous said...

Thank you very much. Is there a easy way to get the first day and the last day of the previous quarter?

Suprotim Agarwal said...

To get the First Day and Last Day of 'Last' quarter, try this query

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

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

bill said...

beautiful code!

I needed first and last days of *last* quarter for my requirements, so I did:


bill said...

oops--sorry--didn't see your last comment where you already did the first and last day of last quarter!