t = datetime()
t = datetime(y, m, d)
t = datetime(y, m, d, h, mi, s)
t = datetime(text, 'InputFormat', fmt)
t = datetime(x, 'ConvertFrom', kind)
| Parameter | Description |
|---|---|
| inputs | Year, month, day, optional time parts, text input, numeric input, and name-value options such as Format, TimeZone, InputFormat, ConvertFrom, Epoch, and TicksPerSecond. |
| Parameter | Description |
|---|---|
| output | A datetime array storing serial date values plus display format and timezone metadata. |
Create datetime arrays from calendar parts, text, or numeric date representations.
Use datetime to construct temporal values used by the other date and time functions. Numeric matrices with three or six columns are interpreted as date vectors; scalar and array components are expanded to a common size.
string returns the formatted text of each element and <missing> for NaT; the display, char and cellstr keep the text NaT (cellstr(d, fmt) uses the format fmt). datetime(missing), and assigning missing into a datetime array, give NaT.
datetime.empty(m, n, ...) returns an empty datetime array; growing an array by assignment fills the new elements with NaT. A comparison with missing is false (~= is true), as with NaT.
TimeZone names a time zone (for example 'Europe/Paris', 'UTC', a fixed offset '+05:30', a duration offset, or 'local' for the system time zone). Setting it on a datetime that has a time zone keeps the same instants and moves the wall clock; on a datetime without one it keeps the wall clock. posixtime and juliandate inputs are UTC instants. Datetimes of different time zones compare, subtract and concatenate by instant (in the time zone of the first operand); a datetime with a time zone never combines with one without. A wall-clock time skipped by a daylight saving change moves after the gap, an ambiguous one is standard time, and fixed-length durations count elapsed time.
Array-valued inputs keep their data shape when the operation supports arrays. Scalar operands are expanded where the implementation defines scalar expansion.
t = datetime(2024, 5, 17, 13, 14, 15)
[y, m, d] = ymd(t)
posixtime(datetime(1970, 1, 2))
| Version | Description |
|---|---|
| 2.0.0 | initial version |