# months

Number of whole months between dates

## Syntax

``MyMonths = months(StartDate,EndDate)``
``MyMonths = months(___,EndMonthFlag)``

## Description

example

````MyMonths = months(StartDate,EndDate)` returns the number of whole months between `StartDate` and `EndDate`. If `EndDate` is earlier than `StartDate`, `MyMonths` is negative. 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 character vector dates, then `EndDate` must be an n-row character array of character vector dates or a single date. `MyMonths` is then an `N`-by-`1` vector of numbers.```

example

````MyMonths = months(___,EndMonthFlag)` returns the number of whole months between `StartDate` and `EndDate` using an optional argument for `EndMonthFlag`. If `EndDate` is earlier than `StartDate`, `MyMonths` is negative. ```

## Examples

collapse all

Find the number of whole months using date character vectors.

`MyMonths = months('may 31 2000', 'jun 30 2000', 1)`
```MyMonths = 1 ```

Find the number of whole months using date character vectors when the optional `EndMonthFlag` = `0`.

`MyMonths = months('may 31 2000','jun 30 2000', 0)`
```MyMonths = 0 ```

Find the number of whole months using a cell array of date character vectors.

```Dates = ['mar 31 2002'; 'apr 30 2002'; 'may 31 2002']; MyMonths = months(Dates, 'jun 30 2002')```
```MyMonths = 3×1 3 2 1 ```

## Input Arguments

collapse all

Starting date for number of whole months between dates, specified as a serial date number or date character vector.

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 character vector dates, then `EndDate` must be an n-row character array of character vector dates or a single date. `MyMonths` is then an n-by-`1` vector of numbers.

Data Types: `single` | `double` | `char` | `cell`

Ending date for number of whole months between dates, specified as a serial date number or date character vector.

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 character vector dates, then `EndDate` must be an n-row character array of character vector dates or a single date. `MyMonths` is then an n-by-`1` vector of numbers.

Data Types: `single` | `double` | `char` | `cell`

Flag for end-of-month rule, specified as a nonnegative integer with values `0` or `1`.

If `StartDate` and `EndDate` are end-of-month dates and `EndDate` has fewer days than `StartDate`, `EndMonthFlag = 1`. In this case, `EndDate` is treated as the end of a whole month, while `EndMonthFlag = 0` does not.

Data Types: `logical`

## Output Arguments

collapse all

Number of whole months between dates, returned as a nonnegative integer.