## calculate number of months in a period using months

### calculate number of months in a period using months

try to use MONTHS to calculate the number of months in a period (several years)
-what method should i use to write the date? dd-mm-yyyy? or mm-dd.yyyy?
- whatever I do the answer is 1 or -1 or 0 (if not code 504)

Question: does MONTHS calculate the number of months in a given period of time? What should I do to get a result?
(I did use the formula wizzard)

OOo 3.0.X on Mac OSx Leopard + Ubuntu, Win XP

Posts: 41
Joined: Tue Nov 27, 2007 9:05 am
Location: Netherlands

### Re: calculate number of months in a period using months

I never used the MONTHS function. Having two dates in cells A1(earlier) and B1(later) and knowing for shure that every year has 12 months exactly:
Code: Select all   Expand viewCollapse view
`=YEAR(B1)*12+MONTH(B1)-YEAR(A1)*12-MONTH(A1)`

Of course this can not work with literal text values.
Test:
Code: Select all   Expand viewCollapse view
`=COUNT(A1:B1)`

returns 2 if both cells have a numeric value (such as valid date).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4

Villeroy
Volunteer

Posts: 28675
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany