calyears

Calendar years, for date arithmetic that follows leap years.

Category: Language Fundamentals > Data Types

Syntax

d = calyears(n)

Creates a calendarDuration of n calendar years.

Description

A calendar year keeps the month and day and increases the year, so it is always a true anniversary, whether the year has 365 or 366 days. February 29 plus one calendar year becomes February 28.

Calendar durations can be combined: calyears(2) + calmonths(3) is shown as 2y 3mo.

Input arguments

n
Numeric array of year counts.

Output arguments

d
calendarDuration array, same size as n.

Example

Anniversary and combination

datetime(2024,2,29) + calyears(1)
calyears(2) + calmonths(3)
Output
ans = datetime
   28-Feb-2025
ans = calendarDuration
   2y 3mo

See also

calmonths caldays years calendarDuration