user32023: I'm doing a project and I want to get the amount of time between two sensor inputs.  i.e. the sensor detects something, and it triggers a timer, and when the sensor picks up something else, it stops the timer and stores the amount of time the passed in a variable.  Is there a library or a specific function that exists?

user7508: Just adding a few notes to the perfectly valid answers you already got:
On your typical AVR-based Arduino, micros() has a resolution of
4 µs and millis() is updated every 1024 µs. This last point
implies that millis() increments most times by 1 ms, but
occasionally by 2 ms. Keep this in mind if time resolution is an
issue.
Both millis() and micros() return 32-bit unsigned numbers. This
implies that millis() overflows (it rolls-over to zero) roughly every
49.7 days and micros() every 71.6 min. This limits the
maximum interval length you can measure with each of those functions. It
does not limit the maximum run time of your program, since
subtracting two timestamps does work fine across a rollover
event.

user4143: It's simple enough to make a "helper" function to give you the number of milliseconds between each call of the function:
uint32_t millisSince() {
    static uint32_t lastMillis = millis();
    uint32_t now = millis();
    uint32_t diff = now - lastMillis;
    lastMillis = now;
    return diff;
}

Every time you call that it will return the amount of time that has passed since you last called it. The first time it will return 0 since it has never been called before.

32023: <p>I'm doing a project and I want to get the amount of time between two sensor inputs.  i.e. the sensor detects something, and it triggers a timer, and when the sensor picks up something else, it stops the timer and stores the amount of time the passed in a variable.  Is there a library or a specific function that exists?</p>
 7508: <p>Just adding a few notes to the perfectly valid answers you already got:</p>

<p>On your typical AVR-based Arduino, <code>micros()</code> has a resolution of
4&nbsp;µs and <code>millis()</code> is updated every 1024&nbsp;µs. This last point
implies that <code>millis()</code> increments most times by 1&nbsp;ms, but
occasionally by 2&nbsp;ms. Keep this in mind if time resolution is an
issue.</p>

<p>Both <code>millis()</code> and <code>micros()</code> return 32-bit unsigned numbers. This
implies that <code>millis()</code> overflows (it rolls-over to zero) roughly every
49.7&nbsp;days and <code>micros()</code> every 71.6&nbsp;min. This limits the
maximum interval length you can measure with each of those functions. It
does <strong>not</strong> limit the maximum run time of your program, since
<a href="https://arduino.stackexchange.com/a/12588">subtracting two timestamps does work fine across a rollover
event</a>.</p>
 4143: <p>It's simple enough to make a "helper" function to give you the number of milliseconds between each call of the function:</p>

<pre><code>uint32_t millisSince() {
    static uint32_t lastMillis = millis();
    uint32_t now = millis();
    uint32_t diff = now - lastMillis;
    lastMillis = now;
    return diff;
}
</code></pre>

<p>Every time you call that it will return the amount of time that has passed since you last called it. The first time it will return 0 since it has never been called before.</p>
