calendarDuration
Lengths of time in calendar units: years, months, days and a time of day.
Category: Language Fundamentals > Data Types
Syntax
d = calendarDuration(y, m, d)
Builds a duration of y years, m months and d days.
d = calendarDuration(y, m, d, h, mi, s)
Also includes hours, minutes and seconds.
Description
A calendarDuration keeps years, months, days and time of day as separate components. calendarDuration(1,2,3) therefore means one year, two months and three days, not a fixed number of seconds. Its effect is decided when it is added to a datetime.
The shortcut constructors calyears, calmonths, calweeks and caldays create a single component, and these can be added: calyears(1) + calmonths(2).
Input arguments
y, m, d- Years, months and days (integers).
h, mi, s- Hours, minutes and seconds.
Output arguments
d- calendarDuration object. Its actual length in days depends on the date it is added to.
Example
Build and add
d = calendarDuration(1,2,3)
datetime(2020,1,31) + d
Output
d = calendarDuration
1y 2mo 3d
ans = datetime
03-Apr-2021