May 23, 2009

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

Did you like this post?
kick it on
subscribe via rss subscribe via e-mail
print this post follow me on twitter

About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal



9 Responses to "Find First and Last Day of the Current Quarter in SQL Server"
  1. darksander said...
    February 18, 2010 at 5:52 AM

    Thanks a lot for your gem :)

  2. Serginho said...
    July 9, 2010 at 1:07 PM

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

    It's really a gem.

  3. Anonymous said...
    July 12, 2010 at 12:06 AM

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

    Thanks :)

  4. Anonymous said...
    August 10, 2010 at 12:42 AM

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

    If possible plz Mention d logic

    ......MAster ANil

  5. shalala said...
    October 13, 2010 at 1:08 PM
    This comment has been removed by the author.
  6. Anonymous said...
    October 13, 2010 at 1:09 PM

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

  7. Suprotim Agarwal said...
    October 13, 2010 at 9:06 PM

    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

  8. bill said...
    January 12, 2011 at 10:49 AM

    beautiful code!

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


  9. bill said...
    January 12, 2011 at 10:51 AM

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


Copyright © 2009-2016 All Rights Reserved for by Suprotim Agarwal | Terms and Conditions