eomday

Number of days in a month.

Category: Language Fundamentals > Data Types

Syntax

d = eomday(y, m)

Last day of month m in year y.

Description

The year matters only for February: it has 29 days in leap years, that is, years divisible by 4 except those divisible by 100 unless also divisible by 400, so eomday(1900,2) is 28 and eomday(2000,2) is 29. Arrays y and m of the same size, or one scalar, work element by element.

Input arguments

y
Year (integer array).
m
Month, from 1 to 12.

Output arguments

d
Double array: 28, 29, 30 or 31.

Example

Month lengths

eomday(2024, 1:12)
eomday([1900 2000 2023 2024], 2)
Output
ans = 1×12

    31    29    31    30    31    30    31    31    30    31    30    31
ans = 1×4

    28    29    28    29

See also

eomdate datenum calendar datetime