# NQL time\_elapsed()

The `time_elapsed()` function calculates the time elapsed since an event. The function returns the values in seconds.

Use this function with a field of *datetime* [data type](/platform/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-syntax-overview/nql-data-types.md), for example:

* the `last_seen` field from the `devices` table
* `time` from the `device_performance.boots` table

The timeframe specified in your query does not restrict the values returned by the `time_elapsed()` function. For example, the following query retrieves only devices active in the past day, but the values returned by `time_elapsed()` may extend beyond that timeframe.

<figure><img src="/files/12cXcfDDP8MU1Wh2USIk" alt=""><figcaption></figcaption></figure>

### Using with the ‘where’ clause <a href="#nqltime_elapsed-usingwiththewhereclause" id="nqltime_elapsed-usingwiththewhereclause"></a>

Use the `time_elapsed()` function in a `where` clause.

**Example:**

Retrieve the list of devices where the last operating system update was more than 15 days ago.

{% code overflow="wrap" lineNumbers="true" %}

```
devices
| where operating_system.last_update.time_elapsed() > 15d
```

{% endcode %}

### Using with the ‘list’ clause <a href="#nqltime_elapsed-usingwiththelistclause" id="nqltime_elapsed-usingwiththelistclause"></a>

Use the `time_elapsed()` function in a `list` clause.

**Example:**

List devices and the time elapsed from their last startup.

{% code overflow="wrap" lineNumbers="true" %}

```
devices
| include device_performance.boots
| where type == fast_startup
| compute last_fast_startup_time = time.last()
| list name, last_fast_startup_time.time_elapsed()
```

{% endcode %}

| Name            | Last fast startup time → time elapsed |
| --------------- | ------------------------------------- |
| device-10d267d2 | 1w 0d 1h 8min 22s 0ms                 |
| device-d1d5abc9 | 17h 38min 22s 0ms                     |
| device-5117c4c3 | 3w 1d 10h 33min 8s 0ms                |
| device-16834449 | 57min 18s 0ms                         |
| …               | …                                     |

### Using with the ‘compute’ clause <a href="#nqltime_elapsed-usingwiththecomputeclause" id="nqltime_elapsed-usingwiththecomputeclause"></a>

Use the `time_elapsed()` function in a `compute` clause.

**Example:**

List devices and the time elapsed from their last startup. Applying chaining of functions (call multiple functions on the same field).

{% code overflow="wrap" lineNumbers="true" %}

```
devices
| include device_performance.boots
| where type == fast_startup
| compute time_since_last_fast_startup = time.last().time_elapsed()
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nexthink.com/platform/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions/nql-time_elapsed.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
