| Financial Toolbox | Search  Help Desk |
| datenum | Examples See Also |
Syntax
n = datenum(ds) n = datenum(ds,p) n = datenum(y, mo, d) n = datenum(y, mo, d, h, mi, s) n = datenum(dn)
Description
n = datenum(ds) returns a serial date number n given a date string ds. Date numbers are the number of days that has passed since a base date. In MATLAB, date number 1 is January 1, 0000 A.D. If the input includes time components, the date number includes a fractional component. If the input is only a time component, the date number is only a fractional time component.
The date string ds can be any of several forms:
'19-may-1995' 'may 19, 1995' '19-may-95' '19-may' (current year assumed) '5/19/95' '5/19' (current year assumed) '19-may-1995, 18:37' '19-may-1995, 6:37 pm' '5/19/95/18:37' '5/19/95/6:37 pm' '18:37'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(ds,p)
assumes that two-character years lie within the 100-year period beginning with the pivot year p . The default pivot year is the current year minus 50 years.
n = datenum(y, mo, d)
returns a serial date number n given year, month, and day integers y, mo, and d.
n = datenum(y, mo, d, h, mi, s)
returns a serial date number n given year, month, day, hour, minute, and second integers y, mo, d, h, mi, and s.
n = datenum(dn) returns a serial date number n given a serial date number dn.
Note:
Examples
n = datenum('19-may-1995')
n = 728798
n = datenum('5/19/95')
n = 728798
n = datenum('19-may-1995, 6:37 pm')
n = 728798.78
n = datenum('5/19/95/18:37')
n = 728798.78
n = datenum('6:37 pm')
n = 0.78
n = datenum(1995, 5, 19)
n = 728798
n = datenum(1995, 1:6, 19)
n = [728678 728709 728737 728768 728798 728829]
n = datenum(1995, 5, 19, 18, 37, 0)
n = 728798.78
n = datenum(728798)
n = 728798
The next example demonstrates the use of the pivot year in interpreting date strings with two-character years.
n = datenum(`12-june-12')
n =
735032
datestr(735032)
ans =
12-Jun-2012
n = datenum(`12-june-12',1900)
n =
698507
datestr(698507)
ans =
12-Jun-1912
See Also
datestr, datevec, daysact, now, today