| Financial Toolbox | Search  Help Desk |
| months | Examples See Also |
Number of whole months between dates.
Syntax
mm = months(d1, d2, eom)
mm = months(d1, d2)
Description
mm = months(d1, d2, eom)
returns the number of whole months between two dates d1 and d2. If d2 is earlier than d1, mm is negative. Enter dates as serial date numbers or date strings.
eom is the end-of-month flag. If d1 and d2 are end-of-month dates and d2 has fewer days than d1, eom = 1 (default) treats d2 as the end of a whole month, while eom = 0 does not.
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 d1 is an N-row character array of date strings, then d2 must be an N-row character array of date strings or a single date. mm is then an N-by-1 vector of numbers.
Examples
mm = months('may 31 1997', 'jun 30 1997', 1)
mm =
1
mm = months('may 31 1997','jun 30 1997', 0)
mm =
0
d1 = ['mar 31 1997'; 'apr 30 1997'; 'may 31 1997'];
mm = months(d1, 'jun 30 1997')
mm =
3
2
1
See Also
yearfrac