month

Returns the month of a given date string, s.

Syntax

[R, name] = month(s)

[R,...] = month(s, fmt)

Inputs

s
A string representing a date. By default, if no fmt is specified, s is expected to be in the format dd-mmm-yyyy.
Type: string
fmt (optional)
Returns the given format that s is in. Valid formats that can return month are:
  • 'dd-mmm-yyyy HH:MM:SS'
  • 'dd-mmm-yyyy'
  • 'mm/dd/yy'
  • 'mmm'
  • 'm'
  • 'mm'
  • 'mm/dd'
  • 'mmmyy'
  • 'dd/mm'
  • 'dd/mm/yy'
  • 'mmm.dd,yyyy HH:MM:SS'
  • 'mmm.dd,yyyy'
  • 'mm/dd/yyyy'
  • 'dd/mm/yyyy'
  • 'yy/mm/dd'
  • 'yyyy/mm/dd'
  • 'mmmyyyy'
  • 'yyyy-mm-dd'
  • 'yyyymmddTHHMMSS'
  • 'yyyy-mm-dd HH:MM:SS'
Type: string

Outputs

R
Month number from the given date s
Type: integer
name
Short description of the month name from the given date s
Type: string

Examples:

Return the month from a date string in the default date format:
R = month('10-Apr-2019')
R = 4
Return the month number and name from a date string in the specific date format:
[R, name] = month('Apr.04,2019 10:11:12', 'mmm.dd,yyyy HH:MM:SS')
R = 4
name = Apr