Get the first day of past three months from current month

  • Hi ...

    I wrote this expression: =DateAdd("m", -3, DateSerial(Year(Now()), Month(Now()), 1)) this is giving me 5/1/2011.

    IS this correct ?

    Thanks,

    Komal

  • Looks pretty good to me. Test it with a few dates other than Now() and you will probably find that you will get what you want.

  • Here is a large number of date routines that you might want to save for future reference.

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

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • From the link in my prior post .. have some fun with finding the 1st day of the prior month

    DECLARE @I INT

    SET @I = 0

    WHILE @I < 13

    BEGIN

    select dateadd(mm, datediff(mm, 0, GETDATE()) - @I, 0) AS 'Firstof month',

    DATENAME ( dw ,dateadd(mm, datediff(mm, 0, GETDATE()) - @I, 0) ) AS 'First day of month'

    SET @I = @I + 1

    END

    Shorened sample of the results:

    First of month First day of month

    ----------------------- ---------------------

    2011-08-01 00:00:00.000 Monday

    2011-07-01 00:00:00.000 Friday

    2011-06-01 00:00:00.000 Wednesday

    2011-05-01 00:00:00.000 Sunday

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Thank you....I have another issue with datepart .I have @Year and @Month values comming from Parameter.

    I need to write expression to get the 12month rolling date ,selected month and year values from parameters.

    I tried with previous expression in ssrs but getting errors.Any other way to get 12 month date?

    Thanks,

    Komal

  • What do you mean by a 12 month date?

  • I want to get the past 12months date depending on the parameters chosen from report!!!!! I need to write an expression to get it...but getting errors:

    =DATEADD("MM",DATEDIFF("MM",0,Parameters!RunMonth.Value)-11,0)

    tried different ways...:(

  • komal145 (8/4/2011)


    I want to get the past 12months date depending on the parameters chosen from report!!!!! I need to write an expression to get it...but getting errors:

    =DATEADD("MM",DATEDIFF("MM",0,Parameters!RunMonth.Value)-11,0)

    tried different ways...:(

    Just slightly confused!!!!! (Were all those explanation points really needed?)

    Please provide an example of what the date range would be based on a specific date input.

Viewing 8 posts - 1 through 7 (of 7 total)

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