Calculating MONTH

  •  

    Hi,

    Start date and end date was an example.

    Ok - i've done it wrong. What I'm tring to do is the following.

    In the query builder..         This will get the month from both dates and subtract it

    x: Month([FirstTreatment])

    y: Month([AssesmentDate])

    TimeOnWaitingList: ([x]-[y])

    This works. But if I had the dates

    05/01/2006 as x

    27/04/2005 as y   The difference should be 11 but I get -3

    HELP Please

  • Try playing with this.

    datediff(month, '04/27/2005', '01/05/2006')

    I get 9 months and the dates are in US format but it should be a start

  • Ritesh,

    You should have continued this in your original thread.

    This is a continuation from:

    http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=23&messageid=264425

    -SQLBill

  • You should calcualte the month difference together with year. Use datediff()

    Your statement,

    month('05/01/2006') will return 1

    month('27/04/2005') will return 4

    so 1 - 4 = -3. Which is correct but not what you wanted !

    use datediff(month, '2005-04-27', '2006-01-05') and it will return you 9

  • This works. But if I had the dates

    05/01/2006 as x

    27/04/2005 as y The difference should be 11 but I get -3

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

    aslo the above should return differece of 9 not 11. How did you get 11 anyway ?

Viewing 5 posts - 1 through 4 (of 4 total)

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