years - Duration in years - MATLAB (original) (raw)

Main Content

Syntax

Description

Y = years([X](#bud6n6u-1-X)) returns an array of fixed-length years equivalent to the values in the input array.

The years function converts between duration and double values. To display a duration in units of years, set its Format property to 'y'.

Leap years have one extra day. To create an array of calendar years that account for leap years when used in calendar calculations, use thecalyears function.

example

Examples

collapse all

Y = 2×3 duration 1 yr 3 yrs 5 yrs 10 yrs 12 yrs 15 yrs

Find the difference between two arrays of dates. The output is a duration array.

t1 = datetime(2007:2010,10,1); t2 = datetime(2014,05,1); dt = t2 - t1

dt = 1×4 duration 57696:00:00 48912:00:00 40152:00:00 31392:00:00

Convert each duration in dt to a number of fixed-length years.

Y = 1×4

6.5819    5.5799    4.5805    3.5812

Input Arguments

collapse all

Input array, specified as a numeric array, duration array, or logical array.

Extended Capabilities

expand all

Theyears function fully supports tall arrays. For more information, see Tall Arrays.

Version History

Introduced in R2014b