

Amazon Timestream for LiveAnalytics に類似した機能をご希望の場合は Amazon Timestream for InfluxDB をご検討ください。リアルタイム分析に適した、シンプルなデータインジェストと 1 桁ミリ秒のクエリ応答時間を特徴としています。詳細については、[こちら](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)を参照してください。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 日付/時間関数
<a name="date-time-functions"></a>

**注記**  
Timestream for LiveAnalytics は負の時間値をサポートしていません。負の時間になるオペレーションはエラーになります。

Timestream for LiveAnalytics は、日付と時刻に UTC タイムゾーンを使用します。Timestream は、次の日付と時刻の関数をサポートしています。

**Topics**
+ [一般および変換](#date-time-functions-general)
+ [間隔と期間](#date-time-functions-interval-duration)
+ [フォーマットと解析](#date-time-functions-formatting-parsing)
+ [抽出](#date-time-functions-extraction)

## 一般および変換
<a name="date-time-functions-general"></a>

Timestream for LiveAnalytics は、日付と時刻に関する次の一般的な関数と変換関数をサポートしています。


| 関数 | 出力データ型 | 説明 | 
| --- | --- | --- | 
| current\_date | date | UTC で現在の日付を返します。括弧は使用されません。<pre>SELECT current_date</pre><br />結果の例: `2022-07-07` これは予約キーワードでもあります。予約キーワードの一覧については、「[予約済みキーワード](ts-limits.md#limits.reserved)」を参照してください。  | 
| current\_time | 時間 | UTC で現在の時刻を返します。括弧は使用されません。<pre>SELECT current_time</pre><br />結果の例: `17:41:52.827000000` これは予約キーワードでもあります。予約キーワードの一覧については、「[予約済みキーワード](ts-limits.md#limits.reserved)」を参照してください。  | 
| current\_timestamp または now() | timestamp | UTC で現在のタイムスタンプを返します。<pre>SELECT current_timestamp</pre><br />結果の例: `2022-07-07 17:42:32.939000000` これは予約キーワードでもあります。予約キーワードの一覧については、「[予約済みキーワード](ts-limits.md#limits.reserved)」を参照してください。  | 
| current\_timezone() | varchar<br />値は「UTC」になります。 | Timestream は、日付と時刻に UTC タイムゾーンを使用します。<pre>SELECT current_timezone()</pre><br />結果の例: `UTC` | 
| date(varchar(x))、date(timestamp) | date | <pre>SELECT date(TIMESTAMP '2022-07-07 17:44:43.771000000')</pre>結果の例: `2022-07-07` | 
| last\_day\_of\_month(timestamp)、last\_day\_of\_month(date) | date | <pre>SELECT last_day_of_month(TIMESTAMP '2022-07-07 17:44:43.771000000')</pre>結果の例: `2022-07-31` | 
| from\_iso8601\_timestamp(string) | timestamp | ISO 8601 タイムスタンプを内部タイムスタンプ形式に解析します。<pre>SELECT from_iso8601_timestamp('2022-06-17T08:04:05.000000000+05:00')</pre><br />結果の例: `2022-06-17 03:04:05.000000000` | 
| from\_iso8601\_date(string) | date | ISO 8601 の日付文字列を、指定された日付の UTC 00:00:00 の内部タイムスタンプ形式に解析します。<pre>SELECT from_iso8601_date('2022-07-17')</pre><br />結果の例: `2022-07-17` | 
| to\_iso8601(timestamp)、to\_iso8601(date) | varchar | 入力の ISO 8601 形式の文字列を返します。<pre>SELECT to_iso8601(from_iso8601_date('2022-06-17'))</pre><br />結果の例: `2022-06-17` | 
| from\_milliseconds(bigint) | timestamp | <pre>SELECT from_milliseconds(1)</pre>結果の例: `1970-01-01 00:00:00.001000000` | 
| from\_nanoseconds(bigint) | timestamp | <pre>select from_nanoseconds(300000001)</pre>結果の例: `1970-01-01 00:00:00.300000001` | 
| from\_unixtime(double) | timestamp | 指定された unixtime に対応するタイムスタンプを返します。<pre>SELECT from_unixtime(1)</pre><br />結果の例: `1970-01-01 00:00:01.000000000` | 
| localtime | 時間 | UTC で現在の時刻を返します。括弧は使用されません。<pre>SELECT localtime</pre><br />結果の例: `17:58:22.654000000` これは予約キーワードでもあります。予約キーワードの一覧については、「[予約済みキーワード](ts-limits.md#limits.reserved)」を参照してください。  | 
| localtimestamp | timestamp | UTC で現在のタイムスタンプを返します。括弧は使用されません。<pre>SELECT localtimestamp</pre><br />結果の例: `2022-07-07 17:59:04.368000000` これは予約キーワードでもあります。予約キーワードの一覧については、「[予約済みキーワード](ts-limits.md#limits.reserved)」を参照してください。  | 
| to\_milliseconds(interval day to second)、to\_milliseconds(timestamp) | bigint | <pre>SELECT to_milliseconds(INTERVAL '2' DAY + INTERVAL '3' HOUR)</pre>結果の例: `183600000`<pre>SELECT to_milliseconds(TIMESTAMP '2022-06-17 17:44:43.771000000')</pre><br />結果の例: `1655487883771` | 
| to\_nanoseconds(interval day to second)、to\_nanoseconds(timestamp) | bigint | <pre>SELECT to_nanoseconds(INTERVAL '2' DAY + INTERVAL '3' HOUR)</pre>結果の例: `183600000000000`<pre>SELECT to_nanoseconds(TIMESTAMP '2022-06-17 17:44:43.771000678')</pre><br />結果の例: `1655487883771000678` | 
| to\_unixtime(timestamp) | double | 指定されたタイムスタンプの unixtime を返します。<pre>SELECT to_unixtime('2022-06-17 17:44:43.771000000')</pre><br />結果の例: `1.6554878837710001E9` | 
| date\_trunc(unit, timestamp) | timestamp | 単位に切り捨てられたタイムスタンプを返します。単位は [秒、分、時間、日、週、月、四半期、年] のいずれかです。<pre>SELECT date_trunc('minute', TIMESTAMP '2022-06-17 17:44:43.771000000')</pre><br />結果の例: `2022-06-17 17:44:00.000000000` | 

## 間隔と期間
<a name="date-time-functions-interval-duration"></a>

Timestream for LiveAnalytics は、日付と時刻に関する次の間隔関数と期間関数をサポートしています。


| 関数 | 出力データ型 | 説明 | 
| --- | --- | --- | 
| date\_add(unit, bigint, date)、date\_add(unit, bigint, time)、date\_add(varchar(x), bigint, timestamp) | timestamp | 単位の bigint を追加します。単位は [秒、分、時間、日、週、月、四半期、年] のいずれかです。<pre>SELECT date_add('hour', 9, TIMESTAMP '2022-06-17 00:00:00')</pre><br />結果の例: `2022-06-17 09:00:00.000000000` | 
| date\_diff(unit, date, date)、date\_diff(unit, time, time)、date\_diff(unit, timestamp, timestamp) | bigint | 差を返します。単位は [秒、分、時間、日、週、月、四半期、年] のいずれかです。<pre>SELECT date_diff('day', DATE '2020-03-01', DATE '2020-03-02')</pre><br />結果の例: `1` | 
| parse\_duration(string) | interval | 入力文字列を解析して `interval` の同値を返します。<pre>SELECT parse_duration('42.8ms')</pre><br />結果の例: `0 00:00:00.042800000`<pre>SELECT typeof(parse_duration('42.8ms'))</pre><br />結果の例: `interval day to second` | 
| bin(timestamp, interval) | timestamp | `timestamp` パラメータの整数値を、`interval` パラメータの整数値の最も近い倍数に切り下げます。<br />この戻り値の意味は明確でない場合があります。最初に整数演算を使用してタイムスタンプ整数を間隔整数で除算し、次にその結果を間隔整数で乗算して計算します。<br />タイムスタンプは、POSIX エポック (1970 年 1 月 1 日) から経過した 1 秒の小数点以下の数値として UTC ポイントを指定することに注意してください。戻り値が暦の単位と一致することはほとんどありません。例えば、30 日間の間隔を指定すると、エポックからのすべての日が増分で 30 日単位に分割され、暦月とは関係のない直近の増分の 30 日の開始値が返されます。<br />次に例を示します。<pre>bin(TIMESTAMP '2022-06-17 10:15:20', 5m)     ==> 2022-06-17 10:15:00.000000000<br />bin(TIMESTAMP '2022-06-17 10:15:20', 1d)     ==> 2022-06-17 00:00:00.000000000<br />bin(TIMESTAMP '2022-06-17 10:15:20', 10day)  ==> 2022-06-17 00:00:00.000000000<br />bin(TIMESTAMP '2022-06-17 10:15:20', 30day)  ==> 2022-05-28 00:00:00.000000000</pre> | 
| ago(interval) | timestamp | current\_timestamp `interval` に対応する値を返します。<pre>SELECT ago(1d)</pre><br />結果の例: `2022-07-06 21:08:53.245000000` | 
| 1h、1d、30m などの間隔リテラル | interval | 間隔リテラルは、parse\_duration(string) の便利な機能です。例えば、`1d` は `parse_duration('1d')` と同じです。これにより、間隔が使用されるすべての場所でリテラルを使用できます。例えば、`ago(1d)` と `bin({{<timestamp>}}, 1m)` です。 | 

一部の間隔リテラルは、parse\_duration の簡易表現として機能します。例えば、`parse_duration('1day')`、`1day`、`parse_duration('1d')`、`1d` はそれぞれ、型が `interval day to second` である `1 00:00:00.000000000` を返します。スペースは、`parse_duration` の指定された形式で許可されます。例えば、`parse_duration('1day')` は `00:00:00.000000000` も返します。ただし、`1 day` は間隔リテラルではありません。

`interval day to second` に関連する単位は、ns、ナノ秒、us、マイクロ秒、ms、ミリ秒、s、秒、m、分、h、時間、d、日です。

`interval year to month` もあります。interval year to month に関連する単位は、y、年、月です。例えば、`SELECT 1year` は `1-0` を返します。`SELECT 12month` も `1-0` を返します。`SELECT 8month` は `0-8` を返します。

`quarter` の単位は、`date_trunc`、`date_add`、`quarter` などの一部の関数でも使用できますが、間隔リテラルの一部としては使用できません。

## フォーマットと解析
<a name="date-time-functions-formatting-parsing"></a>

Timestream for LiveAnalytics は、日付と時刻に関する次のフォーマット関数と解析関数をサポートしています。


| 関数 | 出力データ型 | 説明 | 
| --- | --- | --- | 
| date\_format(timestamp, varchar(x)) | varchar | この関数で使用される書式指定子の詳細については、[https://trino.io/docs/current/functions/datetime.html\#mysql-date-functions](https://trino.io/docs/current/functions/datetime.html#mysql-date-functions) を参照してください。<pre>SELECT date_format(TIMESTAMP '2019-10-20 10:20:20', '%Y-%m-%d %H:%i:%s')</pre><br />結果の例: `2019-10-20 10:20:20` | 
| date\_parse(varchar(x), varchar(y)) | timestamp | この関数で使用される書式指定子の詳細については、[https://trino.io/docs/current/functions/datetime.html\#mysql-date-functions](https://trino.io/docs/current/functions/datetime.html#mysql-date-functions) を参照してください。<pre>SELECT date_parse('2019-10-20 10:20:20', '%Y-%m-%d %H:%i:%s')</pre><br />結果の例: `2019-10-20 10:20:20.000000000` | 
| format\_datetime(timestamp, varchar(x)) | varchar | この関数で使用される書式文字列の詳細については、[http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html](http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html) を参照してください。<pre>SELECT format_datetime(parse_datetime('1968-01-13 12', 'yyyy-MM-dd HH'), 'yyyy-MM-dd HH')</pre><br />結果の例: `1968-01-13 12` | 
| parse\_datetime(varchar(x), varchar(y)) | timestamp | この関数で使用される書式文字列の詳細については、[http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html](http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html) を参照してください。<pre>SELECT parse_datetime('2019-12-29 10:10 PST', 'uuuu-LL-dd HH:mm z')</pre><br />結果の例: `2019-12-29 18:10:00.000000000` | 

## 抽出
<a name="date-time-functions-extraction"></a>

Timestream for LiveAnalytics は、日付と時刻に関する次の抽出関数をサポートしています。抽出関数は利便性が高く、残りの関数の基礎となります。


| 関数 | 出力データ型 | 説明 | 
| --- | --- | --- | 
| extract | bigint | タイムスタンプからフィールドを抽出します。ここで、フィールドは [YEAR、QUARTER、MONTH、WEEK、DAY、DAY\_OF\_MONTH、DAY\_OF\_WEEK、DOW、DAY\_OF\_YEAR、DOY、YEAR\_OF\_WEEK、YOW、HOUR、MINUTE、SECOND] のいずれかです。<pre>SELECT extract(YEAR FROM '2019-10-12 23:10:34.000000000')</pre><br />結果の例: `2019` | 
| day(timestamp)、day(date)、day(interval day to second) | bigint | <pre>SELECT day('2019-10-12 23:10:34.000000000')</pre>結果の例: `12` | 
| day\_of\_month(timestamp)、day\_of\_month(date)、day\_of\_month(interval day to second) | bigint | <pre>SELECT day_of_month('2019-10-12 23:10:34.000000000')</pre>結果の例: `12` | 
| day\_of\_week(timestamp)、day\_of\_week(date) | bigint | <pre>SELECT day_of_week('2019-10-12 23:10:34.000000000')</pre>結果の例: `6` | 
| day\_of\_year(timestamp)、day\_of\_year(date) | bigint | <pre>SELECT day_of_year('2019-10-12 23:10:34.000000000')</pre>結果の例: `285` | 
| dow(timestamp)、dow(date) | bigint | day\_of\_week のエイリアス | 
| doy(timestamp)、doy(date) | bigint | day\_of\_year のエイリアス | 
| hour(timestamp)、hour(time)、hour(interval day to second) | bigint | <pre>SELECT hour('2019-10-12 23:10:34.000000000')</pre>結果の例: `23` | 
| millisecond(timestamp)、millisecond(time)、millisecond(interval day to second) | bigint | <pre>SELECT millisecond('2019-10-12 23:10:34.000000000')</pre>結果の例: `0` | 
| minute(timestamp)、minute(time)、minute(interval day to second) | bigint | <pre>SELECT minute('2019-10-12 23:10:34.000000000')</pre>結果の例: `10` | 
| month(timestamp)、month(date)、month(interval year to month) | bigint | <pre>SELECT month('2019-10-12 23:10:34.000000000')</pre>結果の例: `10` | 
| nanosecond(timestamp)、nanosecond(time)、nanosecond(interval day to second) | bigint | <pre>SELECT nanosecond(current_timestamp)</pre>結果の例: `162000000` | 
| quarter(timestamp)、quarter(date) | bigint | <pre>SELECT quarter('2019-10-12 23:10:34.000000000')</pre>結果の例: `4` | 
| second(timestamp)、second(time)、second(interval day to second) | bigint | <pre>SELECT second('2019-10-12 23:10:34.000000000')</pre>結果の例: `34` | 
| week(timestamp)、week(date) | bigint | <pre>SELECT week('2019-10-12 23:10:34.000000000')</pre>結果の例: `41` | 
| week\_of\_year(timestamp)、week\_of\_year(date) | bigint | 週のエイリアス | 
| year(timestamp)、year(date)、year(interval year to month) | bigint | <pre>SELECT year('2019-10-12 23:10:34.000000000')</pre>結果の例: `2019` | 
| year\_of\_week(timestamp)、year\_of\_week(date) | bigint | <pre>SELECT year_of_week('2019-10-12 23:10:34.000000000')</pre>結果の例: `2019` | 
| yow(timestamp)、yow(date) | bigint | year\_of\_week のエイリアス | 