Date of day in future or past month
Any input can contain multiple values, but if so, all other inputs must contain the same
number of values or a single value that applies to all. For example, if
StartDate is an n-row datetime, then
NumberMonths must be an
1 vector of integers or a single
TargetDate is then an
1 vector of datetimes.
StartDate is a string or date character vector,
TargetDate is returned as a serial date number. Use the
datestr to convert serial date
numbers to formatted date character vectors.
StartDate is a datetime array, then
returned as a datetime array.
Determine the Dates of Days in a Future Month
TargetDate in a future month using a datetime for
StartDate = datetime(1997,6,3); NumberMonths = 6; DayFlag = 0; Basis = 0; EndMonthRule = 1; TargetDate = datemnth(StartDate, NumberMonths, DayFlag,Basis, EndMonthRule)
TargetDate = datetime 03-Dec-1997
TargetDate in a future month using a vector for
NumberMonths = [1; 3; 5; 7; 9]; TargetDate = datemnth(datetime(2001,1,31), NumberMonths)
TargetDate = 5x1 datetime 28-Feb-2001 30-Apr-2001 30-Jun-2001 31-Aug-2001 31-Oct-2001
StartDate — Start date
datetime array | string array | date character vector
Start date, specified as an
N vector using a datetime
array, string array, or date character vectors.
To support existing code,
accepts serial date numbers as inputs, but they are not recommended.
NumberMonths — Number of months in future (positive) or past (negative)
positive or negative integers
Number of months in future (positive) or past (negative), specified
containing positive or negative integers.
DayFlag — Flag for how actual day number for target date in future or past month is determined
0 (day number should be the
day in the future or past month corresponding to the actual day number
of the start date) (default) | numeric with values
Flag for how the actual day number for the target date in future
or past month is determined, specified as an
using a numeric with values
Possible values are:
0(default) = day number should be the day in the future or past month corresponding to the actual day number of the start date.
1= day number should be the first day of the future or past month.
2= day number should be the last day of the future or past month.
This flag has no effect if
Basis — Day-count basis of the instrument
0 (actual/actual) (default) | numeric with value
13 | vector of numerics with values
Day-count basis to be used when determining the past or future
date, specified as a scalar value with an integer with value of
of integers with values of
0 = actual/actual (default)
1 = 30/360 (SIA)
2 = actual/360
3 = actual/365
4 = 30/360 (BMA)
5 = 30/360 (ISDA)
6 = 30/360 (European)
7 = actual/365 (Japanese)
8 = actual/actual (ICMA)
9 = actual/360 (ICMA)
10 = actual/365 (ICMA)
11 = 30/360E (ICMA)
12 = actual/365 (ISDA)
13 = BUS/252
For more information, see Basis.
EndMonthRule — End-of-month rule flag for month having 30 or fewer days
0 (not in effect) (default) | nonnegative integer
End-of-month rule flag for month having 30 or fewer days, specified
as a scalar with a nonnegative integer
or as an
0= Ignore rule, meaning that rule is not in effect.
1= Set rule on, meaning that if you are beginning on the last day of a month, and the month has 30 or fewer days, you will end on the last actual day of the future or past month regardless of whether that month has 28, 29, 30 or 31 days.
EndOfMonthRuleonly applies when you input a date that corresponds to the end of month as the
StartDate. For example, if you enter 02/28/2023 as the
EndOfMonthRuleguarantees that the return date matches the last day of the month in the target output date.
ans = '30-Jun-2023'
datemnthreturns the target date as the last day of June even though the
DayFlagis specified to return the first day of June.
TargetDate — Target date in the future or past month
Target date in the future or past month, returned as an
Version HistoryIntroduced before R2006a
R2022b: Serial date numbers not recommended
datemnth supports serial date numbers,
datetime values are recommended instead. 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 convert serial date numbers or text to
datetime values, use the
datetime function. For example:
t = datetime(738427.656845093,"ConvertFrom","datenum"); y = year(t)
y = 2021
There are no plans to remove support for serial date number inputs.