Dates and Time
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.
Create 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|
Split Dates and Times
Extract Components by Time Unit
|Month number and name|
|Day number or name|
Split into Numeric Arrays
Determine Type, Time Zone Offset, Leap Seconds
|Determine if input is datetime array|
|Determine if input is duration array|
|Determine if input is calendar duration array|
|Determine if input times are regular with respect to time or calendar unit|
|Determine NaT (Not-a-Time) elements|
|Determine daylight saving time elements|
|Determine weekend elements|
|List all leap seconds supported by |
|List time zones|
|Time zone offset from UTC|
Shift or Calculate Differences Between Dates
Convert to Numbers and Strings
Convert to Numbers
|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|
Convert to Strings
Current Date and Time as Numbers or String
|Current date and time as serial date number|
|Current date and time as date vector|
|Current date as character vector|
Day of Calendar Week or Month
Elapsed Time as Number
|Time elapsed between date vectors|
datetime arrays to store date
and time information. These arrays support arithmetic, sorting, comparisons,
plotting, and formatted display.
- Generate Sequence of Dates and Time
- Convert Between Datetime Arrays, Numbers, and Text
- Extract or Assign Date and Time Components of Datetime Array
- Combine Date and Time from Separate Variables
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,
might interpret your input date vectors as vectors of serial date numbers—or interpret
serial date numbers as date vectors—and return unexpected output.