Past 3 months from today

  • I have this query which almost does what I need it to do.

    It returns a date of 2010-03-18 08:46:54.027

    How do you get it to return 2010-03-01

    The time portion doesn't matter it can be 00:00:00

    SELECT DATEADD(m, -3, GETDATE())


    Kindest Regards,

  • I'm not clear what you want it to do, but the following link has a lot of good utility date calculations and can probably lead you to what you need.

    http://qa.sqlservercentral.com/blogs/lynnpettis/archive/2009/3/25/some-common-date-routines.aspx


    And then again, I might be wrong ...
    David Webb

  • Hi,

    From that link I was able to work out what I needed to do.

    This is what I needed, I needed to get the first day of the month of the current year 3 months ago from today.

    DATEADD(Month, DATEDIFF(MONTH, 0, GETDATE()) -3, 0)

    Returns,

    2010-03-01 00:00:00.000


    Kindest Regards,

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

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