Documentation/Calc Functions/MONTHS

Function name:
MONTHS

Category:
Date and Time

Summary:
Calculates the number of months between two dates.

Syntax:
MONTHS(StartDate; EndDate; Type)

Returns:
Returns an integer value which is the difference between the two given dates in months, depending on the calculation mode selected through the Type argument.

Arguments:
StartDate is the date (in quotation marks) or a date-time serial number, or a reference to the cell containing one of those types, which is either the start date or the end date of the period for which the calculation is to be carried out.

EndDate is the date (in quotation marks) or a date-time serial number, or a reference to the cell containing one of those types, which is either the end date or the start date of the period for which the calculation is to be carried out.

Type is an integer value, either 0 or 1. If Type is 0, then MONTHS returns the number of whole months between StartDate and EndDate (day of the month to day of the month). If Type is 1, MONTHS identifies the month that each of StartDate and EndDate lie in, and then returns the difference between those months. See the and  sections below for more detail.


 * If either StartDate or EndDate is not a valid date expression, then MONTHS reports a #VALUE! error.


 * If StartDate is earlier than EndDate, the result is a positive number; if StartDate is later than EndDate, the result is a negative number.


 * MONTHS ignores any time components of StartDate and EndDate.


 * If Type is non-numeric, then MONTHS reports a #VALUE! error.


 * If Type is a non-integer value, then MONTHS truncates it to an integer.


 * If (after truncation) Type is not equal to either 0 or 1, then MONTHS reports an invalid argument error (Err:502).

Details specific to MONTHS function
If Type is set to 1, the equation for MONTHS is
 * MONTHS = MONTH(EndDate) - MONTH(StartDate) + 12 * (YEAR(EndDate) - YEAR(StartDate)).

If Type is set to 0, the value calculated above is adjusted as follows:
 * If (StartDate is earlier than EndDate) and (DAY(StartDate) > DAY(EndDate)) then subtract 1
 * If (StartDate is later then EndDate) and (DAY(StartDate) < DAY(EndDate)) then add 1.

MONTHS is not part of the ODF 1.2 international standard and should not be regarded as portable.

Related LibreOffice functions:
DAYS

YEARS

ODF standard:
None.

Equivalent Excel functions:
None.