| Financial Toolbox | ![]() |
Number of whole months between dates
Syntax
Arguments
Description
Months = months(StartDate, EndDate, returns the number of whole months between EndMonthFlag)
StartDate and EndDate. If EndDate is earlier than StartDate, Months is negative. Enter dates as serial date numbers or date strings.
Any input argument can contain multiple values, but if so, all other inputs must contain the same number of values or a single value that applies to all. For example, if StartDate is an n-row character array of date strings, then EndDate must be an n-row character array of date strings or a single date. Months is then an n-by-1 vector of numbers.
Examples
Months = months('may 31 2000', 'jun 30 2000', 1) Months = 1 Months = months('may 31 2000','jun 30 2000', 0) Months=0Dates = ['mar 31 2002'; 'apr 30 2002'; 'may 31 2002']; Months = months(Dates, 'jun 30 2002') Months = 3 2 1
See Also
yearfrac
| month | movavg | ![]() |