0

# Compute months between to dates

Hi,

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

Thanks.

7replies Oldest first
• Oldest first
• Popular
• Hi:

month(date2) - month(date1)

Best regards, Alex

Like

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,

Like
• Laura
• Laura
• 4 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)

Like
• 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

Like
• Laura
• Laura
• 4 yrs ago
• Reported - view

Like
• @Maria

What would you like to do ?

Like
• 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”

Like
Like Follow
• 2 yrs agoLast active
• 7Replies
• 2336Views