Dates and Time - MATLAB & Simulink (original) (raw)

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

expand all

Points in Time

datetime Arrays that represent points in time
dateshift Shift date or generate sequence of dates and times
NaT Not-a-Time
eomday Last day of month
lweekdate (Not recommended; use dateshift) Date of last occurrence of weekday in month
nweekdate (Not recommended; use dateshift) Date of specific occurrence of weekday in month

Durations

Calendar Durations

Calendar of Month

Points in Time in Alternate Formats

datenum (Not recommended; use datetime orduration) Convert date and time to serial date number
now (Not recommended; use datetime) Current date and time as serial date number
clock (Not recommended; use datetime) Current date and time as date vector
date (Not recommended; use datetime("today")) Current date as character vector
today (Not recommended; use datetime("today")) Current date
eomdate (Not recommended; use dateshift) Last date of month

Extract Components

year Year number of input date and time
quarter Quarter number of input date and time
month Month number or name of input date and time
week Week number of input date and time
day Day number or name of input date and time
weekday Day of week
hour Hour component of input date and time
minute Minute component of input date and time
second Seconds component of input date and time
weeknum (Not recommended; use week) Week in year

Split into Components

ymd Year, month, and day numbers of datetime
hms Hour, minute, and second numbers of datetime or duration
datevec Convert date and time to vector of components
split Split calendar duration into numeric and duration units
time Convert time of calendar duration to duration
timeofday Elapsed time since midnight for datetime arrays

datetime Arrays

between Calendar math differences
caldiff Calendar math successive differences
tzoffset Time zone offset from UTC
dateshift Shift date or generate sequence of dates and times

Fixed-Format Arrays

addtodate (Not recommended; use duration orcalendarDuration) Add time to serial date number
etime (Not recommended; use datetime values or between) Time elapsed between date vectors
months (Not recommended; use between) Number of whole months between dates
isbetween Determine which elements are within specified range
isregular Determine if input times are regular with respect to time or calendar unit
isnat Determine NaT (Not-a-Time) elements
isdst Determine daylight saving time elements
isweekend Determine weekend elements
isdatetime Determine if input is datetime array
isduration Determine if input is duration array
iscalendarduration Determine if input is calendar duration array
string String array
char Character array
datestr (Not recommended; use string or char) Convert date and time to string format

Conversions

convertTo Convert datetime values to numeric representations
exceltime Convert MATLAB datetime to Excel date number
posixtime Convert MATLAB datetime to POSIX time
juliandate Convert MATLAB datetime to Julian date
yyyymmdd Convert MATLAB datetime to YYYYMMDD numeric value
m2xdate (Not recommended; use exceltime) MATLAB date to Excel serial date number
x2mdate (Not recommended; use datetime) Excel serial date number to MATLAB serial date number or datetime value

Times in MATLAB

Topics

Troubleshooting