MATLAB Function Reference    
datenum

Serial date number

Syntax

Description

The datenum function converts date strings and date vectors into serial date numbers. Date numbers are serial days elapsed from some reference date. By default, the serial day 1 corresponds to 1-Jan-0000.

N = datenum(str) converts the date string str into a serial date number. 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.

N = datenum(str,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.

N = datenum(Y,M,D) returns the serial date number for corresponding elements of the Y, M, and D (year, month, day) arrays. Y, M, and D must be arrays of the same size (or any can be a scalar). Values outside the normal range of each array are automatically "carried" to the next unit.

N = datenum(Y,M,D,H,MI,S) returns the serial date number for corresponding elements of the Y, M, D, H, MI, and S (year, month, hour, minute, and second) array values. Y, M, D, H, MI, and S must be arrays of the same size (or any can be a scalar).

Examples

Convert a date string to a serial date number.

Specifying year, month, and day, convert a date to a serial date number.

Convert a date string to a serial date number using the default pivot year

Convert the same date string to a serial date number using 1900 as the pivot year.

See Also

datestr, datevec, now


 date datestr