t2 = datetime
02-Jun-2014
Calendar Duration Arithmetic
Create two calendar durations and then find their sum.
d1 = calyears(1) + calmonths(2) + caldays(20)
d1 = calendarDuration
1y 2mo 20d
d2 = calmonths(11) + caldays(23)
d2 = calendarDuration
11mo 23d
d = d1 + d2
d = calendarDuration
2y 1mo 43d
When you sum two or more calendar durations, a number of months greater than 12 roll over to a
number of years. However, a large number of days does not roll over to a number of months, because
different months consist of different numbers of days.
Increase d by multiplying it by a factor of 2. Calendar duration values must be integers, so you can
multiply them only by integer values.
2*d
ans = calendarDuration
4y 2mo 86d
Calculate Elapsed Time in Exact Units
Subtract one datetime array from another to calculate elapsed time in terms of an exact number of
hours, minutes, and seconds.
Find the exact length of time between a sequence of datetime values and the start of the previous
day.
t2 = datetime('now') + caldays(1:3)
t2 = 1x3 datetime
02-Sep-2021 13:47:22
03-Sep-2021 13:47:22
04-Sep-2021 13:47:22
t1 = datetime('yesterday')
t1 = datetime
31-Aug-2021
dt = t2 - t1
Date and Time Arithmetic
7-31
Précédent

- 285/1450

Suivant