month
Month number of a datetime.
Category: Language Fundamentals > Data Types
Syntax
m = month(t)
Returns the month, 1 for January to 12 for December, of each element of t.
Description
month is a shortcut for the month field of datetime. Its companions year, day, hour, minute and second return the other fields. The number is used to group data by month or to build date conditions such as month(t) == 12.
Input arguments
t- datetime array.
Output arguments
m- Double array of the same size as
t.
Example
Months of some dates
t = datetime(2024,3,5) + calmonths(0:3);
month(t)
month(datetime(2024,12,25)) == 12
Output
ans = 1×4
3 4 5 6
ans = logical
1
Notes
MatLivre accepts only datetime, duration or calendarDuration input. The 'name' and 'shortname' options of MATLAB return the month number instead of text, so build names with datestr or string(t, 'MMMM').