# NQL datetime関数

Datetime関数は、タイムスタンプフィールドから時刻の成分（例えば、時、曜日、月の日など）を返します。 これにより、例えば営業時間、営業週、または月中特定の日など、時間ウィンドウ内のパターンやトレンドを識別することができます。

## 例

過去24時間以内の営業時間中のデバイスパフォーマンスデータを取得します。

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

```
device_performance.events during past 24h
| where start_time.hour() >= 9 and end_time.hour() <= 17
```

{% endcode %}

## 利用可能な関数

### 時間()

**説明**: この関数は指定されたタイムスタンプから時間を抽出します。

**戻り値**: 0から23までの数字。

**NQLクエリの例**: 例えば、9時から17時の営業時間中に発生したすべてのイベントを表示します。

```
device_performance.events during past 24h
| where start_time.hour() >= 9 and end_time.hour() <= 17
```

{% hint style="info" %}
日にちから時間を抽出するには、クエリに分または時間で表現された時間枠を使用する必要があります。例えば、`during past 7d`の代わりに`during past 168h`を使用してください。
{% endhint %}

### 日()

**説明**: この関数は指定された日付から月の日を抽出します。

**戻り値**: 1から31までの数字。

**NQLクエリの例**: 月の第1週からデバイスパフォーマンスデータを取得します。

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

```
device_performance.events during past 30d
| where start_time.day() >= 1 and end_time.day() <= 7
```

{% endcode %}

### day\_of\_week()

**説明**: この関数は指定された日付から曜日を抽出します。

**戻り値**: 数字の1は月曜日、7は日曜日を表します。

**NQLクエリの例**: 平日の月曜日から金曜日までのデバイスパフォーマンスデータを取得します。

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

```
device_performance.events during past 30d
| where start_time.day_of_week() >= 1 and end_time.day_of_week() < 6
```

{% endcode %}

## タイムゾーンパラメーター

デフォルトでは、システムはローカルタイムゾーンの時間値を返し、Datetime関数はローカル時間で値を返します。 関数内で`タイムゾーン`パラメーターを使用して、異なるタイムゾーンを指定します。 Datetime関数は指定されたタイムゾーンで値を返します。 詳しくは、[datetime関数でサポートされているタイムゾーン](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions/nql-date-time-functions/supported-timezones-in-datetime-functions.md)を参照してください。

{% hint style="info" %}
Datetime関数は、指定されたタイムゾーンでのタイムスタンプの時間成分を取得しますが、時間の選択に使用する時間枠を変更することはありません。

特定の時間選択形式が、クエリに含められた時間枠にどのように影響するかに関しては、[NQL時間選択](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-syntax-overview/nql-time-selection.md#nqltimeselection-timezones)を参照してください。
{% endhint %}

**例**

ヘルシンキ（EETタイムゾーン）で午前8時にいて、ロンドン（GMTタイムゾーン）の営業時間中のデバイスパフォーマンスデータを取得したい場合。 ロンドンの営業時間にデータを絞り込むには、次のクエリを使用します。

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

```
device_performance.events during past 24h
| where start_time.hour(timezone = 'GMT') >= 9 and end_time.hour(timezone = 'GMT') <= 17
```

{% endcode %}

以下の画像は、同じクエリですが`list`句に異なる時間形式が含まれています。 時間枠と戻り値は、時間形式に依存します。

* 時間枠は現在のタイムゾーンの時間を反映します。
* `start_time`は、イベントのタイムスタンプ全体を現在のタイムゾーンで返します。
* `start_time.hour()`は、イベントの時間を現在のタイムゾーンで返します。
* `start_time.hour(timezone = 'GMT')`は、イベントの時間をロンドンのタイムゾーンで返します。

<figure><img src="/files/VY6gFDQy72Xf0gluXjqx" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
クエリの時間枠選択がDatetime関数で使用されるタイムゾーンのオフセットを含むのに十分な大きさであることを確認してください。
{% endhint %}


---

# 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/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions/nql-date-time-functions.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.
