# etime

(Not recommended; use datetime values or between) Time elapsed between date vectors

etime is not recommended. Use datetime values instead. To calculate the elapsed time between two datetime values, either subtract one from the other or use the between function. For more information on updating your code, see Version History or Replace Discouraged Instances of Serial Date Numbers and Date Strings.

## Description

example

e = etime(t2,t1) returns the number of seconds between two date vectors or matrices of date vectors, t1 and t2.

Note: To measure the time required to run code, use timeit, or tic and toc, instead of etime. For more information, see Tips.

## Examples

collapse all

Compute the time elapsed between a specified time and the current time.

Specify the initial date and time as the start of January 2020. Convert it to date vector form.

t1 = datevec('2020-01-01')
t1 = 1×6

2020           1           1           0           0           0

Determine the current date and time by using the datetime function.

t2 = datetime("now")
t2 = datetime
26-Nov-2022 07:17:01

Convert the current date and time to a date vector.

t2 = datevec(t2)
t2 = 1×6
103 ×

2.0220    0.0110    0.0260    0.0070    0.0170    0.0012

You can compute the number of seconds between t1 and t2 by using etime.

e = etime(t2,t1)
e = 9.1610e+07

However, the etime function is not recommended. In particular, it is not recommended for measuring the time it takes to run your code.

## Input Arguments

collapse all

Date vectors, specified as 1-by-6 vectors or m-by-6 matrices containing m full date vectors in the format:[Year Month Day Hour Minute Second].

Example: [2012 03 27 11 50 01]

Data Types: double

## Tips

• To time the duration of an event, use the timeit or tic and toc functions instead of etime and clock. The clock function is based on the system time, which can be adjusted periodically by the operating system, and thus might not be reliable in time comparison operations.

## Algorithms

etime does not account for the following:

• Leap seconds