Convert date and time to serial date number
The datenum
function creates a numeric array that
represents each point in time as the number of days from January 0, 0000. The
numeric values also can represent elapsed time in units of days. However, the best
way to represent points in time is by using the datetime
data
type. The best way to represent elapsed time is by using the
duration
or calendarDuration
data
types.
DateNumber = datenum(t)
DateNumber = datenum(DateString)
DateNumber = datenum(DateString,formatIn)
DateNumber = datenum(DateString,PivotYear)
DateNumber = datenum(DateString,formatIn,PivotYear)
DateNumber = datenum(DateVector)
DateNumber = datenum(Y,M,D)
DateNumber = datenum(Y,M,D,H,MN,S)
converts the datetime or duration values in the input array
DateNumber
= datenum(t
)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]
.
To create arbitrarily shaped output, use the datenum(Y,M,D)
and datenum(Y,M,D,H,MN,S)
syntaxes.
The datenum(DateVector)
syntax creates only a column
vector of date numbers.
datenum(2013,[1 3; 2 4],ones(2,2))
ans = 735235 735294 735266 735325