Method Reference: calendarDuration.split

calendarDuration: […] = split (calD, units)

Split calendarDuration array into numeric and duration units.

[…] = split (calD, units) splits the calendar duration units in calD into separate numeric arrays according to date/time units specified in units, which must be either a cell array of character vectors or a string array containing any of the following date/time units in descending order.

  1. 'years'
  2. 'quarters'
  3. 'months'
  4. 'weeks'
  5. 'days'
  6. 'time'

When a single date/time unit is specified, units may also be a character vector. When 'time' is specified in units, the corresponding returned argument is a duration array. The values of years, quarters, and months are computed independently from the values of weeks and days in calD, with larger units taking precedence when specified The same applies for duration arrays, when requested.

Source Code: calendarDuration

Example: 1

split decomposes a calendar duration into the whole-unit components you request, distributing the span across them. (Contrast the single-unit extractors such as calmonths, which each return the span as a total in one unit.)

 d = calendarDuration (2, 3, 40)
d =
  calendarDuration

   2y 3mo 40d
 [y, mo, days] = split (d, {'years', 'months', 'days'});
 [y, mo, days]
ans =

    2    3   40