Three months before current month

  • I need to set [OrderDate] three months before current month.

    For example, as if June,

    [OrederDate] should be "Between '1/1/2013' and '03/31/2013'.

    For July, [OrederDate] should be "Between '1/1/2013' and '04/30/2013'.

    I want to use code like

    [OrederDate] Between @datefrom and @dateto

    I set @datefrom = '01/01/2013' (always), how to set @dateto three months before current month?

  • One way to achieve the results..

    DECLARE @datefrom DATETIME

    DECLARE @dateto DATETIME

    SET@datefrom = '01/01/2013'

    SET@dateto = DATEADD(DAY,-1,DATEADD(MONTH,DATEDIFF(MONTH,0,CURRENT_TIMESTAMP)-2,0))

    SELECT @datefrom,@dateto


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • It works great.

    Thank you.

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

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