Dates and Time
The date and time data typesdatetime
,duration
, andcalendarDuration
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, seeRepresent Dates and Times in MATLABor watchDate and Time Arrays.
Functions
Topics
Represent Dates and Times in MATLAB
Usedatetime
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 twodatetime
arrays or twoduration
arrays using relational operators, such as>
and<
.
Set Date and Time Display Format
TheFormat
property ondatetime
,duration
, andcalendarDuration
arrays controls the display of values in each array. You can change the value of this property. Changing theFormat
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.
Core Functions Supporting Date and Time Arrays
Many functions in MATLAB operate on date and time arrays in much the same way that they operate on other arrays.
Troubleshooting
Carryover in Date Vectors and Strings
If an element falls outside the conventional range, MATLAB adjusts both that date vector element and the previous element.
Converting Date Vector Returns Unexpected Output
Because a date vector is a 1-by-6 vector of numbers,datestr
might interpret your input date vectors as vectors of serial date numbers, or vice versa, and return unexpected output.