years

Creates durations measured in fixed-length years, or converts durations to years.

Category: Language Fundamentals > Data Types

Syntax

d = years(x)

Returns a duration of x years for numeric x.

x = years(d)

Returns the number of years in the duration d as a double.

Description

A fixed-length year is exactly 365.2425 days, the mean length of a Gregorian year, so years(1) == days(365.2425). It does not follow the calendar: adding years(1) to a date adds that many days, not the same calendar date next year. For calendar-aware steps use calyears.

Fractions are fine, and durations can be added, scaled and compared like numbers.

Input arguments

x
Numeric array of year counts.
d
A duration array.

Output arguments

d
A duration array, displayed with the unit yrs.
x
Double array of years.

Example

d = years([1 2.5])
days(years(1))
Output
d = 1×2 duration array

      1 yr   2.5 yrs
ans = 365.2425

See also

days hours calyears duration year