Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    3

    Unanswered: Date difference in months

    Hi to all,

    I want to make an sql query that will subtract two dates and the difference will be number in months.

    i have this table TestTable with Fields ACost, Adate, AMonth

    my formula is this X = (Now-Adate), should give me number in months
    and Y = (ACost/AMonth)
    i want to get the product of X and Y, (X*Y).

    how can i make this in sql views?

    can anyone help me with this?

    thanks a lot!


    best regards,

    saldiboy

  2. #2
    Join Date
    Jan 2003
    Location
    India
    Posts
    523
    how about

    create view testview as


    select ((datediff(m,Adate, getdate())) * (ACost/Amonth)) as val from testTable

  3. #3
    Join Date
    Feb 2006
    Posts
    3
    you're genius man!

    thanks!

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Just beware that DateDiff() actually counts boundaries, not units. So for example there is a month between 2006-02-28 and 2006-03-02, which occaisionally surprises folks.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •