Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

years

Duration in years

Syntax

Y = years(X)

Description

example

Y = years(X) returns an array of years equivalent to the values in X.

  • If X is a numeric array, then Y is a duration array in units of fixed-length years. A fixed-length year is equal to 365.2425 days.

  • If X is a duration array, then Y is a double array with each element equal to the number of fixed-length years in the corresponding element of X.

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

Examples

collapse all

X = [1 3 5; 10 12 15]
X = 

     1     3     5
    10    12    15

Y = years(X)
Y = 2x3 duration array
     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 = 1x4 duration array
   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 = years(dt)
Y = 

    6.5819    5.5799    4.5805    3.5812

Input Arguments

collapse all

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

Tips

  • years creates fixed-length years. To create an array of calendar years that account for leap days when used in calendar calculations, use the calyears function.

Extended Capabilities

See Also

Introduced in R2014b

Was this topic helpful?