datetime

Methods

Method Reference: datetime.diff

datetime: D = diff (A)
datetime: D = diff (A, N)
datetime: D = diff (A, N, dim)

Differences between successive datetime elements.

D = diff (A) returns a duration array holding the elapsed time between successive elements of A along its first non-singleton dimension. The differences are computed from the absolute instants, so for a zoned array they are aware of daylight saving time transitions (a calendar day spanning a transition is 23 or 25 hours, not 24). Not-A-Time elements propagate as NaN durations.

D = diff (A, N) applies diff recursively N times, returning the N-th order difference. N must be a positive integer scalar.

D = diff (A, N, dim) operates along dimension dim.

Source Code: datetime

diff returns the elapsed time between successive elements as a duration array.

 t = datetime (2024, 1, [1, 3, 8, 15])
t =
  1x4 datetime array

    01-Jan-2024    03-Jan-2024    08-Jan-2024    15-Jan-2024
 diff (t)
ans =
  1x3 duration array

    48:00:00    120:00:00    168:00:00