# NQL time\_elapsed()

`time_elapsed()` 関数はイベントからの経過時間を計算します。 関数は値を秒単位で返します。

この関数は *datetime* [データ型](https://docs.nexthink.com/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-syntax-overview/nql-data-types) のフィールドと共に使用します。例えば:

* `devices` テーブルの `last_seen` フィールド
* `device_performance.boots` テーブルの `time`

クエリで指定した期間は、`time_elapsed()` 関数により返される値を制限しません。 例えば、次のクエリは過去1日にアクティブだったデバイスのみを取得しますが、`time_elapsed()`により返される値はそれ以上の期間に及ぶ可能性があります。

<figure><img src="https://3549141153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLm8O7QKZDn6z806e7Sv%2Fuploads%2Fgit-blob-6d03d0d02d89b9fbaae72e3bedff4ab3997d0c29%2Ftime_elapsed_query_example.png?alt=media" alt=""><figcaption></figcaption></figure>

### ‘where’句との使用 <a href="#nqltime_elapsed-usingwiththewhereclause" id="nqltime_elapsed-usingwiththewhereclause"></a>

`where` 句で `time_elapsed()` 関数を使用します。

**例:**

最後のOSアップデートから15日以上経過しているデバイスのリストを取得します。

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

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

{% endcode %}

### ‘list’句との使用 <a href="#nqltime_elapsed-usingwiththelistclause" id="nqltime_elapsed-usingwiththelistclause"></a>

`list` 句で `time_elapsed()` 関数を使用します。

**例:**

デバイスとその最終起動からの経過時間を一覧表示します。

{% 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 %}

| 名前              | 最速起動時間 → 経過時間          |
| --------------- | ---------------------- |
| device-10d267d2 | 1週 0日 1時間 8分 22秒 0ミリ秒  |
| device-d1d5abc9 | 17時間 38分 22秒 0ミリ秒      |
| device-5117c4c3 | 3週 1日 10時間 33分 8秒 0ミリ秒 |
| device-16834449 | 57分 18秒 0ミリ秒           |
| …               | …                      |

### ‘compute’句との使用 <a href="#nqltime_elapsed-usingwiththecomputeclause" id="nqltime_elapsed-usingwiththecomputeclause"></a>

`compute` 句で `time_elapsed()` 関数を使用します。

**例:**

デバイスとその最終起動からの経過時間を一覧表示します。 関数の連鎖を適用する(同じフィールドに複数の関数を呼び出す)。

{% 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 %}
