Main Content

eomday

Last day of month

Description

E = eomday(Y,M) returns the last day of the specified month M in the year Y. The output E is a numeric array. The last day of any month is an integer between 28 and 31, inclusive.

example

Examples

collapse all

Return the last day of January 2022.

E = eomday(2022,1)
E = 
31

Return the last day of every month in 2022.

E = eomday(2022,1:12)
E = 1×12

    31    28    31    30    31    30    31    31    30    31    30    31

The eomday function accounts for leap years. In a leap year, February has an extra day, February 29. For example, 2020 is a leap year.

E = eomday(2020,2)
E = 
29

Find all the leap years between 2000 and 2020. First create an array of year numbers. Then use eomday to find the years when February has 29 days.

Y = 2000:2020;
E = eomday(Y,2);
leapYears = Y(E == 29)
leapYears = 1×6

        2000        2004        2008        2012        2016        2020

Input Arguments

collapse all

Year number, specified as an integer array.

Example: E = eomday(2020,12) specifies 2020 as the year number.

Example: E = eomday(2000:2020,12) specifies an array of year numbers.

Month number, specified as an integer array where each element is an integer between 1 and 12, inclusive. The month numbers correspond to the months listed in the table.

Month Number

Month Name

1

January

2

February

3

March

4

April

5

May

6

June

7

July

8

August

9

September

10

October

11

November

12

December

Example: E = eomday(2020,12) specifies 12 as the month number.

Example: E = eomday(2020,1:6) specifies an array of month numbers.

Version History

Introduced before R2006a