Main Content




y = year(t) returns the ISO year numbers for the datetime values in t. ISO year numbers include a year zero and represent years BCE using negative values. The y output is a double array the same size as t.

y = year(t,yearType) returns the type of year number specified by yearType.

The year function returns the year numbers of datetime values. To assign ISO year values to a datetime array, t, use t.Year and modify the Year property.


collapse all

Extract the year numbers from an array of dates.

t = datetime(2010,05,31):calyears(1):datetime(2015,02,28)
t = 1x5 datetime
   31-May-2010   31-May-2011   31-May-2012   31-May-2013   31-May-2014

y = year(t)
y = 1×5

        2010        2011        2012        2013        2014

Input Arguments

collapse all

Input date and time, specified as a datetime array.

Type of year values, specified as either 'iso' or 'gregorian'.

  • If yearType is 'iso', then year returns the ISO year number, which includes a year zero and represents years BCE using negative values.

  • If yearType is 'gregorian', then year returns the Gregorian year number, which is an unsigned integer. For example, the Gregorian year number for 5 CE and 5 BCE is 5 in both cases. Gregorian year numbers do not have a year zero.

Extended Capabilities

See Also

| | | | |

Introduced in R2014b