Get First day previous quarter from today's date

  • Hello All,

    How do I get first day of last month of previous quarter from today's date? I know my question is little confusing. I need to get 06/01/2014 using t-sql. Can somebody give me a hand on this?

    Thanks,

  • It's easy with some date math.

    You can find common date routines in here to try to understand them:

    http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/

    First we get the first day of current quarter:

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

    The rest is easy as we just need to go one month back.

    SELECT DATEADD( MM, -1, DATEADD(QQ, DATEDIFF(QQ, 0, GETDATE()),0))

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis,

    Thank you for your quick response. I'll play around with the dates to get better understanding. Thanks again.

    Amol

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply