Main Content

month

Month number and name

Description

example

m = month(t) returns the month numbers of the datetime values in t. The m output contains integer values from 1 to 12.

example

m = month(t,monthType) returns the type of month number or name specified by monthType.

The month function returns the month numbers or names of datetime values. To assign month numbers to datetime array t, use t.Month and modify the Month property.

Examples

collapse all

Extract the month numbers from an array of dates.

t = datetime(2014,05,31):caldays(35):datetime(2014,10,15)
t = 1x4 datetime
   31-May-2014   05-Jul-2014   09-Aug-2014   13-Sep-2014

m = month(t)
m = 1×4

     5     7     8     9

Get the month names from an array of dates.

t = datetime(2013,01,01):calweeks(12):datetime(2013,12,31)
t = 1x5 datetime
   01-Jan-2013   26-Mar-2013   18-Jun-2013   10-Sep-2013   03-Dec-2013

m = month(t,'name')
m = 1x5 cell
    {'January'}    {'March'}    {'June'}    {'September'}    {'December'}

Input Arguments

collapse all

Input date and time, specified as a datetime array.

Type of month values, specified as a value in the table.

Value of monthTypeDescription
'monthofyear'Month-of-year number
'name'Full month names, for example, August or September. For NaT datetime values, the month name is the empty character vector, ''.
'shortname'Abbreviated month names, for example, Aug or Sep. For NaT datetime values, the month name is the empty character vector, ''.

Note

month returns month names in the language specified by the Locale option in the Datetime format section of the Preferences panel. To change the default datetime locale, see Set Command Window Preferences.

Output Arguments

collapse all

Month number or name, returned as a numeric array of type double, or a cell array of character vectors. m is the same size as t.

Extended Capabilities

See Also

| | | | |

Introduced in R2014b