0

Compute months between to dates

Hi, 

How can I compute the number of months between two dates ?

Thanks. 

8 replies

null
    • Alexander_Koenig
    • 6 yrs ago
    • Reported - view

    Hi:

    month(date2) - month(date1)

    Best regards, Alex

    • Raphael_Vieira_de_Matos
    • 6 yrs ago
    • Reported - view

    Thanks for your prompt reply. 

    Unfortunately, this formula takes the month in the first date and the month in the second date. The problem is that my dates are separated from more than a year. So, the answer is incorrect.

    If I simply compute the date1 - date2, the answer is expressed in a number of days. I can maybe transform this answer in months but I do not know how ? ;-)

    Best regards, 

    • Laura
    • 6 yrs ago
    • Reported - view

    Hi, Raphael, I'm not sure this will work for your purposes, but I've used this before. For date2 > date 1:

    months ( date2, date1 ) = (year(date2) - year(date1)) * 12 + month(date2) - month(date1)

    • Raphael_Vieira_de_Matos
    • 6 yrs ago
    • Reported - view

    Dear Laura,

    Thanks for your messsage and your idea. Your proposition works perfectly, I only add one in order to take count of the first month (0) : 

    (year(DATE 2) - year(DATE 2)) * 12 + month(DATE 2) - month(DATE 1) + 1 

    • Laura
    • 6 yrs ago
    • Reported - view

    Glad it helped! 

    • Raphael_Vieira_de_Matos
    • 4 yrs ago
    • Reported - view

    @Maria

    What would you like to do ?

    • BFXData
    • Bruno_Miguel_Vitorino_Fi
    • 4 yrs ago
    • Reported - view

    Maybe this could help:

    let a := 'Date of Birth';

    let b := today();

    let myYears := if month(a) <= month(b) then

    year(b) - year(a)

    else year(b) - year(a) - 1

    end;

    let myMonth := if month(a) <= month(b) then

    month(b) - month(a)

    else 12 - month(a) + month(b)

    end;

    myYears + " years - " + myMonth + " months”

    • NetSol Co., Ltd.
    • Bernd_Krell
    • 11 mths ago
    • Reported - view

    There is a wrong symbol at the end. Must be " and not ”.

Content aside

  • 11 mths agoLast active
  • 8Replies
  • 2442Views
  • 1 Following