MATLAB Function Reference
datevec

Date components

• ```C = datevec(A)
C = datevec(A,P)
[Y,M,D,H,MI,S] = datevec(A)
```

Description

```C = datevec(A) ``` splits its input into an `n`-by-6 array with each row containing the vector `[Y,M,D,H,MI,S]`. The first five date vector elements are integers. Input `A` can either consist of strings of the sort produced by the `datestr` function, or scalars of the sort produced by the `datenum` and `now` functions. Date strings with two-character years, e.g., `12-june-12`, are assumed to lie within the 100-year period centered about the current year.

```C = datevec(A,P) ``` uses the specified pivot year as the starting year of the 100-year range in which a two-character year resides. The default pivot year is the current year minus 50 years.

```[Y,M,D,H,MI,S] = datevec(A) ``` returns the components of the date vector as individual variables.

When creating your own date vector, you need not make the components integers. Any components that lie outside their conventional ranges affect the next higher component (so that, for instance, the anomalous June 31 becomes July 1). A zeroth month, with zero days, is allowed.

Examples

An example of using a string as input:

• ```datevec('12/24/1984')

ans =
1984          12          24           0           0           0
```

An example of using a serial date number as input:

• ```t = datenum('12/24/1984')

t =
725000

datevec(t)

ans =
1984          12          24           0           0           0
```

`clock`, `datenum`, `datestr`, `now`