MATLAB Function Reference    

Date components


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.


An example of using a string as input:

An example of using a serial date number as input:

See Also

clock, datenum, datestr, now

  datetick dbclear