Main Content

eomdate

(Not recommended; use dateshift) Last date of month

eomdate is not recommended. Use the dateshift function instead because it accepts datetime values as inputs. For more information on updating your code, see Version History or Replace Discouraged Instances of Serial Date Numbers and Date Strings.

Description

example

DayMonth = eomdate(Date) returns the serial date number of the last date of the month for the given Date.

example

DayMonth = eomdate(Year,Month,outputType) returns the serial date number of the last date of the month for the given year and month. However, if outputType is "datetime", then DayMonth is a datetime array. By default, outputType is "datenum".

Examples

collapse all

Find the last day of the month using Year and Month.

DayMonth = eomdate(2001, 2)
DayMonth = 730910
datestr(DayMonth)
ans = 
'28-Feb-2001'

Find the last day of the month using multiples values for Year and a single Month.

Year = [2002 2003 2004 2005];
DayMonth = eomdate(Year, 2);
datestr(DayMonth)
ans = 4x11 char array
    '28-Feb-2002'
    '28-Feb-2003'
    '29-Feb-2004'
    '28-Feb-2005'

Find the last day of the month using a datetime array for Date.

DayMonth = eomdate(datetime("1-Jan-2015","Locale","en_US"))
DayMonth = datetime
   31-Jan-2015

Find the last day of the month using an outputType for "datetime".

DayMonth = eomdate(2001, 2,"datetime")
DayMonth = datetime
   28-Feb-2001

Input Arguments

collapse all

Date to determine last day of month, specified as a serial date number, date string, or datetime array.

If Date is a serial date number or a date string, DayMonth is returned as a serial date number. If Date is a datetime array, then DayMonth is returned as a datetime array.

Data Types: double | string | char | datetime

Year to determine last date of month, specified as a four-digit nonnegative integer.

Either input argument for Year or Month can contain multiple values, but if so, the other input must contain the same number of values or a single value that applies to all. For example, if Year is a 1-by-n vector of integers, then Month must be a 1-by-n vector of integers or a single integer. DayMonth output is then a 1-by-n vector of date numbers.

Data Types: double

Month to determine last date of month, specified as an integer from 1 through 12.

Either input argument for Year or Month can contain multiple values, but if so, the other input must contain the same number of values or a single value that applies to all. For example, if Year is a 1-by-n vector of integers, then Month must be a 1-by-n vector of integers or a single integer. DayMonth output is then a 1-by-n vector of date numbers.

Data Types: double

Output data type, specified as "datenum" or "datetime". If outputType is "datenum", then DayMonth is a serial date number. However, if outputType is "datetime", then DayMonth is a datetime array.

Data Types: string | char

Output Arguments

collapse all

Last day of the month, returned as a serial date number or datetime array.

Version History

Introduced before R2006a

expand all

R2022a: Not recommended

There are no plans to remove eomdate. However, the dateshift function is recommended instead because it accepts datetime values as inputs. The datetime data type provides flexible date and time formats, storage out to nanosecond precision, and properties to account for time zones and daylight saving time.

To return the last date of a month, call dateshift with the "end" and "month" arguments. If dt is a datetime value, and y and m are numbers representing year and month, then these dateshift syntaxes return the last date of the month as a datetime value.

endMonth = dateshift(dt,"end","month")
endMonth = dateshift(datetime(y,m,1),"end","month")

To convert endMonth to a serial date number, use the convertTo function.

endMonthNum = convertTo(endMonth,"datenum")