Generate Sequence of Dates and Time
In this section...
“Sequence of Datetime or Duration Values Between Endpoints with Step Size” on page 7-
17
“Add Duration or Calendar Duration to Create Sequence of Dates” on page 7-19
“Specify Length and Endpoints of Date or Duration Sequence” on page 7-21
“Sequence of Datetime Values Using Calendar Rules” on page 7-22
Sequence of Datetime or Duration Values Between Endpoints
with Step Size
This example shows how to use the colon (:) operator to generate sequences of datetime
or duration values in the same way that you create regularly spaced numeric vectors.
Use Default Step Size
Create a sequence of datetime values starting from November 1, 2013 and ending on
November 5, 2013. The default step size is one calendar day.
t1 = datetime(2013,11,1,8,0,0);
t2 = datetime(2013,11,5,8,0,0);
t = t1:t2
t = 1x5 datetime array
Columns 1 through 3
01-Nov-2013 08:00:00 02-Nov-2013 08:00:00 03-Nov-2013 08:00:00
Columns 4 through 5
04-Nov-2013 08:00:00 05-Nov-2013 08:00:00
Specify Step Size
Specify a step size of 2 calendar days using the caldays function.
t = t1:caldays(2):t2
Generate Sequence of Dates and Time