eomdate

Last date of month

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 character vector, or datetime array.

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

Use the function datestr to convert serial date numbers to formatted date character vectors or datenum to convert date and time to a serial date number.

Data Types: single | double | 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: single | 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: single | double

Output date format, specified as a character vector with values '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: char

Output Arguments

collapse all

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

Introduced before R2006a