Compute months between to dates
How can I compute the number of months between two dates ?
month(date2) - month(date1)
Best regards, Alex
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 ? ;-)
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)
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
Glad it helped!
What would you like to do ?
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
let myMonth := if month(a) <= month(b) then
month(b) - month(a)
else 12 - month(a) + month(b)
myYears + " years - " + myMonth + " months”
- 3 yrs agoLast active