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
returns the serial date number of the last date of the month for the given year and
month. However, if DayMonth
= eomdate(Year
,Month
,outputType
)outputType
is "datetime"
,
then DayMonth
is a datetime
array. By
default, outputType
is "datenum"
.
Examples
Determine the Last Day of the Month for Various Dates
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
Date
— Date to determine last day of month
serial date number | date string | datetime
array
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
— Year to determine last date of month
four-digit nonnegative integer | vector of four-digit nonnegative integers
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
— Month to determine last date of month
integer from 1
through 12
| vector of integers from 1
through
12
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
outputType
— Output data type
"datenum"
(default) | "datetime"
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
DayMonth
— Last day of month
serial date number | datetime
array
Last day of the month, returned as a serial date number or
datetime
array.
Version History
Introduced before R2006aR2022a: 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")
R2022a: Moved to MATLAB from Financial Toolbox
Previously, eomdate
required Financial Toolbox™.
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)