t1 = datetime
08-Mar-2014
Find future points in time by adding a sequence of fixed-length (24-hour) days.
t2 = t1 + days(0:2)
t2 = 1x3 datetime
08-Mar-2014 00:00:00
09-Mar-2014 00:00:00
10-Mar-2014 01:00:00
Because a daylight saving time shift occurred on March 9, 2014, the third datetime in t2 does not
occur at midnight.
Verify that the difference between each pair of datetime values in t2 is 24 hours.
dt = diff(t2)
dt = 1x2 duration
24:00:00
24:00:00
You can add fixed-length durations in other units such as years, hours, minutes, and seconds by
adding the outputs of the years, hours, minutes, and seconds functions, respectively.
To account for daylight saving time changes, you should work with calendar durations instead of
durations. Calendar durations account for daylight saving time shifts when they are added to or
subtracted from datetime values.
Add a number of calendar days to t1.
t3 = t1 + caldays(0:2)
t3 = 1x3 datetime
08-Mar-2014
09-Mar-2014
10-Mar-2014
View that the difference between each pair of datetime values in t3 is not always 24 hours due to the
daylight saving time shift that occurred on March 9.
dt = diff(t3)
dt = 1x2 duration
24:00:00
23:00:00
Add Calendar Durations to Datetime Array
Add a number of calendar months to January 31, 2014.
t1 = datetime(2014,1,31)
t1 = datetime
31-Jan-2014
t2 = t1 + calmonths(1:4)
Date and Time Arithmetic
7-29
08-Mar-2014
Find future points in time by adding a sequence of fixed-length (24-hour) days.
t2 = t1 + days(0:2)
t2 = 1x3 datetime
08-Mar-2014 00:00:00
09-Mar-2014 00:00:00
10-Mar-2014 01:00:00
Because a daylight saving time shift occurred on March 9, 2014, the third datetime in t2 does not
occur at midnight.
Verify that the difference between each pair of datetime values in t2 is 24 hours.
dt = diff(t2)
dt = 1x2 duration
24:00:00
24:00:00
You can add fixed-length durations in other units such as years, hours, minutes, and seconds by
adding the outputs of the years, hours, minutes, and seconds functions, respectively.
To account for daylight saving time changes, you should work with calendar durations instead of
durations. Calendar durations account for daylight saving time shifts when they are added to or
subtracted from datetime values.
Add a number of calendar days to t1.
t3 = t1 + caldays(0:2)
t3 = 1x3 datetime
08-Mar-2014
09-Mar-2014
10-Mar-2014
View that the difference between each pair of datetime values in t3 is not always 24 hours due to the
daylight saving time shift that occurred on March 9.
dt = diff(t3)
dt = 1x2 duration
24:00:00
23:00:00
Add Calendar Durations to Datetime Array
Add a number of calendar months to January 31, 2014.
t1 = datetime(2014,1,31)
t1 = datetime
31-Jan-2014
t2 = t1 + calmonths(1:4)
Date and Time Arithmetic
7-29
