0

# Compute months between to dates

Hi,

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

Thanks.

## 7replies

• Alexander_Koenig
• 5 yrs ago
• Reported - view

Hi:

month(date2) - month(date1)

Best regards, Alex

• Raphael_Vieira_de_Matos
• 5 yrs ago
• Reported - view

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
• 5 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
• 5 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
• 5 yrs ago
• Reported - view

• Raphael_Vieira_de_Matos
• 3 yrs ago
• Reported - view

@Maria

What would you like to do ?

• BFXData
• Bruno_Miguel_Vitorino_Fi
• 3 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”

## Content aside

• 3 yrs agoLast active
• 7Replies
• 2355Views