The date and time data types
support efficient computations, comparisons, and formatted display of dates
and times. Work with these arrays in the same way that you work with numeric
arrays. You can add, subtract, sort, compare, concatenate, and plot date and
time values. You also can represent dates and times as numeric arrays or as
text. For more information, see Represent Dates and Times in MATLAB or watch Date and Time Arrays.
|Duration in years|
|Duration in days|
|Duration in hours|
|Duration in minutes|
|Duration in seconds|
|Duration in milliseconds|
|Lengths of time in fixed-length units|
|Month number and name|
|Day number or name|
|Determine if input is datetime array|
|Determine if input is duration array|
|Determine if input is calendar duration array|
|Determine NaT (Not-a-Time) elements|
|Determine daylight saving time elements|
|Determine weekend elements|
|List time zones|
|Time zone offset from UTC|
|Convert date and time to serial date number|
|Convert date and time to vector of components|
|Convert MATLAB datetime to Excel date number|
|Convert MATLAB datetime to Julian date|
|Convert MATLAB datetime to POSIX time|
|Convert MATLAB datetime to YYYYMMDD numeric value|
|Modify date number by field|
|Current date and time as serial date number|
|Current date and time as date vector|
|Current date as character vector|
|Time elapsed between date vectors|
datetime arrays to store date
and time information. These arrays support arithmetic, sorting, comparisons,
plotting, and formatted display.
You can perform an element-by-element comparison of
values in two
datetime arrays or two
using relational operators, such as
Format property on
calendarDuration arrays controls the display
of values in each array. You can change the value of this property.
Format property does not change the
values in the array, only their display.
When you create a datetime, it is unzoned by default. If you work with datetime values from multiple time zones or need to account for daylight saving time, you might need to specify a time zone.
Follow these best practices when sharing code that handles dates and time with MATLAB® users in other locales. Write and read dates from other locals.
Many functions in MATLAB operate on date and time arrays in much the same way that they operate on other arrays.
If an element falls outside the conventional range, MATLAB adjusts both that date vector element and the previous element.
Because a date vector is a 1-by-6 vector of numbers,
interpret your input date vectors as vectors of serial date numbers,
or vice versa, and return unexpected output.