Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

month

Month number and name

Syntax

m = month(t)
m = month(t,monthType)

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 array
   31-May-2014   05-Jul-2014   09-Aug-2014   13-Sep-2014

m = month(t)
m = 

     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 array
   01-Jan-2013   26-Mar-2013   18-Jun-2013   10-Sep-2013   03-Dec-2013

m = month(t,'name')
m = 1x5 cell array
    {'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

Was this topic helpful?