Arrays of date and time values that can be displayed in different formats
The date and time data types datetime, duration, and calendarDuration 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.
Functions
Create Date and Time Arrays
Create datetime Arrays
datetime |
Arrays that represent points in time |
NaT |
Not-a-Time |
Create duration Arrays
Create calendarDuration Arrays
Split Dates and Times
Extract Components by Time Unit
Split into Numeric Arrays
ymd |
Year, month, and day numbers of datetime |
hms |
Hour, minute, and second numbers of datetime or duration |
split |
Split calendar duration into numeric and duration units |
time |
Convert time of calendar duration to duration |
timeofday |
Elapsed time since midnight for datetimes |
Determine Type, Time Zone Offset, Leap Seconds
Shift or Calculate Differences Between Dates
between |
Calendar math differences |
caldiff |
Calendar math successive differences |
dateshift |
Shift date or generate sequence of dates and time |
isbetween |
Determine elements within date and time interval |
Convert to Numbers and Strings
Convert to Numbers
datenum |
Convert date and time to serial date number |
convertTo |
Convert datetime values to numeric representations |
datevec |
Convert date and time to vector of components |
exceltime |
Convert MATLAB datetime to Excel date number |
juliandate |
Convert MATLAB datetime to Julian date |
posixtime |
Convert MATLAB datetime to POSIX time |
yyyymmdd |
Convert MATLAB datetime to YYYYMMDD numeric value |
addtodate |
Modify date number by field |
Convert to Strings
char |
Character array |
string |
String array |
datestr |
Convert date and time to string format |
Current Date and Time as Numbers or String
now |
Current date and time as serial date number |
clock |
Current date and time as date vector |
date |
Current date as character vector |
Day of Calendar Week or Month
Elapsed Time as Number
etime |
Time elapsed between date vectors |