datenum
(Not recommended; use datetime
or
duration
) Convert date and time to serial date
number
datenum
is not recommended. To represent points in time, use
datetime
arrays. To represent
elapsed times, use duration
or calendarDuration
arrays. For more
information on updating your code, see Version History or
Replace Discouraged Instances of Serial Date Numbers and Date Strings.
Syntax
Description
converts the DateNumber
= datenum(t
)datetime
or
duration
values in the input array
t
to serial date numbers.
A serial date number represents the whole and fractional number of days from a fixed, preset date (January 0, 0000) in the proleptic ISO calendar.
converts text representing dates and times to serial date numbers. If
the format used in the text is known, specify the format as
DateNumber
= datenum(DateString
)formatIn
. Syntaxes without
formatIn
are significantly slower than
syntaxes that include it.
uses DateNumber
= datenum(DateString
,formatIn
)formatIn
to interpret the dates and times
represented by DateString
.
uses DateNumber
= datenum(DateString
,PivotYear
)PivotYear
to interpret text that specifies the
year as two characters. If the format used in the text is known,
specify the format as formatIn
. Syntaxes without
formatIn
are significantly slower than
syntaxes that include it.
uses DateNumber
= datenum(DateString
,formatIn
,PivotYear
)formatIn
to interpret the dates and times
represented by DateString
, and
PivotYear
to interpret text that specifies
the year as two characters. You can specify
formatIn
and PivotYear
in
either order.
converts date vectors to serial date numbers, and returns a column
vector of DateNumber
= datenum(DateVector
)m
date numbers, where
m
is the total number of date vectors in
DateVector
.
returns the serial date numbers for corresponding elements of the
DateNumber
= datenum(Y,M,D
)Y
, M
, and
D
(year, month, day) arrays. The arrays must
be of the same size (or any can be a scalar). You also can specify the
input arguments as a date vector, [Y,M,D]
.
additionally returns the serial date numbers for corresponding
elements of the DateNumber
= datenum(Y,M,D,H,MN,S
)H
, MN
, and
S
(hour, minute, and second) arrays. The
arrays must be of the same size (or any can be a scalar). You also can
specify the input arguments as a date vector,
[Y,M,D,H,MN,S]
.
Examples
Input Arguments
Output Arguments
Tips
To create arbitrarily shaped output, use the
datenum(Y,M,D)
anddatenum(Y,M,D,H,MN,S)
syntaxes. Thedatenum(DateVector)
syntax creates only a column vector of date numbers.datenum(2013,[1 3; 2 4],ones(2,2))
ans = 735235 735294 735266 735325