Main Content

year

Year number of input date and time

Description

example

y = year(t) returns the ISO year number for each date and time specified in t. ISO year numbers include a year zero and represent years BCE using negative values.

The y output is a double array. To assign ISO year values to a datetime array, t, use t.Year and modify the Year property.

y = year(t,yearType) returns the type of year number of datetime array t, specified as either "iso" or "gregorian".

Examples

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.

To support existing code that previously required Financial Toolbox™, year also accepts serial date numbers and text as inputs, but they are not recommended. For more information, see Version History.

Type of year values, specified as either 'iso' or 'gregorian'. This argument is valid only when t is a datetime array.

  • 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.

This argument is valid only when t is a datetime array.

Extended Capabilities

Version History

Introduced in R2014b

expand all

See Also

| | | | |