etime
Elapsed time in seconds between two date vectors.
Category: Language Fundamentals > Data Types
Syntax
t = etime(t1, t0)
Returns t1 minus t0, in seconds.
Description
etime converts both date vectors to absolute time and subtracts them, so it handles differences that cross day, month or year boundaries. The usual pattern is to store t0 = clock before some work and call etime(clock, t0) afterward.
For new code, datetime and duration arithmetic is more flexible.
Input arguments
t1, t0- Date vectors
[year month day hour minute second], as returned byclock. Each is a 1-by-6 row.
Output arguments
t- Scalar double: the difference in seconds. It is negative when
t1is earlier thant0.
Example
Across midnight
etime([2024 1 2 0 1 0], [2024 1 1 23 59 0])
etime([2024 1 1 0 0 0], [2024 1 1 0 1 30])
Output
ans = 120
ans = -90