year

Year number of each date in a datetime array.

Category: Language Fundamentals > Data Types

Syntax

y = year(t)

Returns the year of each element of t.

Description

year(t) is the first output of ymd(t). For a datetime it gives the calendar year as an integer such as 2024. For a duration it gives the number of whole fixed-length years of 365.2425 days.

Input arguments

t
A datetime array (or duration or calendarDuration).

Output arguments

y
Double array with the same size as t.

Example

t = [datetime(2020,1,1) datetime(1999,5,5)];
year(t)
Output
ans = 1×2

        2020        1999

Notes

MatLivre requires datetime, duration or calendarDuration input; serial date numbers are rejected.

See also

ymd month day datetime years