Calendar Duration

This data type creates arrays of time elapsed in variable calendar units. This data type provides 5 functions for creating arrays of variable units. 

  • cal months – For creating arrays with the monthly differences in units.
  • call quarters – For creating arrays with quarterly differences in units.
  • calyears – For creating arrays with the yearly difference in units.
  • caldays – For creating arrays with daily differences in units.
  • calweeks – For creating arrays with the weekly differences in units.

Example 3:

Matlab




% MATLAB Code for calendar Duration
calyears(1:2)
calquarters(1)
calmonths(1:5)


Output:

 

We can perform operations on DateTime arrays and calendar duration arrays.

Example 4:

Matlab




% MATLAB code for datetime array
dt = datetime(2022,11,29);
c = calmonths(1:5);
  
dt+c


Output:

This would create a new array with these values:

 

The same could be done with different calendar duration arrays.

Dates and Time in MATLAB

MATLAB provides many ways to deal with date and time in form of DateTime, calendar duration, and duration data types. These data types do not only support storing and representing date-times but, also allow operations on date time. We shall look at these three data types separately.

Similar Reads

DateTime

The datetime data type specifically records/represents an instant in time. For example, the datetime function alone returns the current datetime, accurate up to the second....

Calendar Duration:

...

Duration:

...