Compute months between to dates
Hi,
How can I compute the number of months between two dates ?
Thanks.
8 replies
-
Hi:
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 ? ;-)
Best regards,
-
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)
-
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
-
Glad it helped!
-
@Maria
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
end;
let myMonth := if month(a) <= month(b) then
month(b) - month(a)
else 12 - month(a) + month(b)
end;
myYears + " years - " + myMonth + " months”
-
There is a wrong symbol at the end. Must be " and not ”.
Content aside
- 9 mths agoLast active
- 8Replies
- 2438Views
-
1
Following