> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloud.cdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Date

> 日付関数は、日付、時刻、およびタイムスタンプデータの作成、抽出、または変更に使用できます。

日付リテラル関数は `L_` で始まり、相対的な間隔を使用して日付フィールドをフィルタするために使用されます。日付リテラル関数では `<, >`、および = 演算子はサポートされていますが、`<= and >=` はサポートされていません。

## CURRENT\_DATE

現在の日付値を返します。

**構文**

```bash theme={null}
CURRENT_DATE()
```

**例**

```bash theme={null}
SELECT CURRENT_DATE();
-- Result: 2018-02-01
```

## CURRENT\_TIMESTAMP

データベースシステムの現在のタイムスタンプを datetime 値として返します。この値は GETDATE および SYSDATETIME と同じで、常にローカルタイムゾーンの値です。

**構文**

```bash theme={null}
CURRENT_TIMESTAMP()
```

**例**

```bash theme={null}
SELECT CURRENT_TIMESTAMP();
-- Result: 2018-02-01 03:04:05
```

## DATEADD

指定された数値（符号付き整数）を日付の指定された日付部分に加算した結果の datetime 値を返します。

**構文**

```bash theme={null}
DATEADD (datepart , integer_number , date [, dateformat])
```

**パラメータ**

* **datepart** 指定された数値を加算する日付の部分。有効な値と省略形は、year（yy、yyyy）、quarter（qq、q）、month（mm、m）、dayofyear（dy、y）、day（dd、d）、week（wk、ww）、weekday（dw）、hour（hh）、minute（mi、n）、second（ss、s）、および millisecond（ms）です。
* **number** 加算する数値。
* **date** datetime データ型の式。
* **dateformat** オプションの出力日付形式。

**例**

```bash theme={null}
SELECT DATEADD('d', 5, '2018-02-01');
-- Result: 2018-02-06

SELECT DATEADD('hh', 5, '2018-02-01 00:00:00');
-- Result: 2018-02-01 05:00:00
```

## DATEDIFF

指定された開始日と終了日の間の指定された時間間隔の差（符号付き整数）を返します。

**構文**

```bash theme={null}
DATEDIFF ( datepart , startdate , enddate )
```

**パラメータ**

* **datepart** 開始日と終了日の差の時間間隔となる日付の部分。有効な値と省略形は、day（dd、d）、hour（hh）、minute（mi、n）、second（ss、s）、および millisecond（ms）です。
* **startdate** 開始日の datetime 式。
* **enddate** 終了日の datetime 式。

**例**

```bash theme={null}
SELECT DATEDIFF('d', '2018-02-01', '2018-02-10');
-- Result: 9

SELECT DATEDIFF('hh', '2018-02-01 00:00:00', '2018-02-01 12:00:00');
-- Result: 12
```

## DATEFROMPARTS

指定された年、月、および日の datetime 値を返します。

**構文**

```bash theme={null}
DATEFROMPARTS(integer_year, integer_month, integer_day)
```

**パラメータ**

* **year** 年を指定する整数式。
* **month** 月を指定する整数式。
* **day** 日を指定する整数式。

**例**

```bash theme={null}
SELECT DATEFROMPARTS(2018, 2, 1);
-- Result: 2018-02-01
```

## DATENAME

指定された日付の指定された日付部分を表す文字列を返します。

**構文**

```bash theme={null}
DATENAME(datepart , date)
```

**パラメータ**

* **datepart** 返す日付の部分。有効な値と省略形は、year（yy、yyyy）、quarter（qq、q）、month（mm、m）、dayofyear（dy、y）、day（dd、d）、week（wk、ww）、weekday（dw）、hour（hh）、minute（mi、n）、second（ss、s）、millisecond（ms）、microsecond（mcs）、nanosecond（ns）、および TZoffset（tz）です。
* **date** datetime 式。

**例**

```bash theme={null}
SELECT DATENAME('yy', '2018-02-01');
-- Result: '2018'

SELECT DATENAME('dw', '2018-02-01');
-- Result: 'Thursday'
```

## DATEPART

指定された日付の指定された日付部分を表す文字列を返します。

**構文**

```bash theme={null}
DATEPART(datepart, date [,integer_datefirst])
```

**パラメータ**

* **datepart** 返す日付の部分。有効な値と省略形は、year（yy、yyyy）、quarter（qq、q）、month（mm、m）、dayofyear（dy、y）、day（dd、d）、week（wk、ww）、weekday（dw）、hour（hh）、minute（mi、n）、second（ss、s）、millisecond（ms）、microsecond（mcs）、nanosecond（ns）、TZoffset（tz）、ISODOW、ISO\_WEEK（isoweek、isowk、isoww）、および ISOYEAR です。
* **date** 日付を指定する datetime 文字列。
* **datefirst** 週の最初の曜日を表すオプションの整数。デフォルトは 7（日曜日）です。

**例**

```bash theme={null}
SELECT DATEPART('yy', '2018-02-01');
-- Result: 2018

SELECT DATEPART('dw', '2018-02-01');
-- Result: 5
```

## DATETIMEFROMPARTS

指定された日付部分の datetime 値を返します。

**構文**

```bash theme={null}
DATETIMEFROMPARTS(integer_year, integer_month, integer_day, integer_hour, integer_minute, integer_seconds, integer_milliseconds)
```

**パラメータ**

* **year** 年を指定する整数式。
* **month** 月を指定する整数式。
* **day** 日を指定する整数式。
* **hour** 時を指定する整数式。
* **minute** 分を指定する整数式。
* **seconds** 秒を指定する整数式。
* **milliseconds** ミリ秒を指定する整数式。

**例**

```bash theme={null}
SELECT DATETIMEFROMPARTS(2018, 2, 1, 1, 2, 3, 456);
-- Result: 2018-02-01 01:02:03.456
```

## DATETIME2FROMPARTS

指定された日付部分の datetime 値を返します（異なるパラメータを使用）。

**構文**

```bash theme={null}
DATETIME2FROMPARTS(integer_year, integer_month, integer_day, integer_hour, integer_minute, integer_seconds, integer_fractions, integer_precision)
```

**パラメータ**

* **year** 年を指定する整数式。
* **month** 月を指定する整数式。
* **day** 日を指定する整数式。
* **hour** 時を指定する整数式。
* **minute** 分を指定する整数式。
* **seconds** 秒を指定する整数式。
* **fractions** 秒の小数部を指定する整数式。
* **precision** 小数部の精度を指定する整数式。

**例**

```bash theme={null}
SELECT DATETIME2FROMPARTS(2018, 2, 1, 1, 2, 3, 456, 3);
-- Result: 2018-02-01 01:02:03.456
```

## DATE\_TRUNC

指定された日付部分の精度に日付を切り捨てます。Oracle の TRUNC 関数をモデルにしています。

**構文**

```bash theme={null}
DATE_TRUNC(date, datepart)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。
* **datepart** 有効な datepart 構文については、[Oracle のドキュメント](https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions230.htm#i1002084) を参照してください。

**例**

```bash theme={null}
SELECT DATE_TRUNC('05-04-2005', 'YY');
-- Result: '1/1/2005'

SELECT DATE_TRUNC('05-04-2005', 'MM');
-- Result: '5/1/2005'
```

## DATE\_TRUNC2

指定された日付部分の精度に日付を切り捨てます。PostgreSQL の date\_trunc 関数をモデルにしています。

**構文**

```bash theme={null}
DATE_TRUNC2(datepart, date, [weekday])
```

**パラメータ**

* **datepart** 'millennium'、'century'、'decade'、'year'、'quarter'、'month'、'week'、'day'、'hour'、'minute'、または 'second' のいずれか。
* **date** 日付を指定する datetime 文字列。
* **weekday** 'week' の最初の日として使用するオプションの曜日。'sunday'、'monday' などのいずれか。

**例**

```bash theme={null}
SELECT DATE_TRUNC2('year', '2020-02-04');
-- Result: '2020-01-01'

SELECT DATE_TRUNC2('week', '2020-02-04', 'monday');
-- Result: '2020-02-02', which is\` \`the previous Monday
```

## DAY

指定された日付の日の部分を指定する整数を返します。

**構文**

```bash theme={null}
DAY(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT DAY('2018-02-01');
-- Result: 1
```

## DAYOFMONTH

指定された日付部分の月内の日を返します。

**構文**

```bash theme={null}
DAYOFMONTH(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT DAYOFMONTH('04/15/2000');
-- Result: 15
```

## DAYOFWEEK

指定された日付部分の曜日を返します。

**構文**

```bash theme={null}
DAYOFWEEK(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT DAYOFWEEK('04/15/2000');
-- Result: 7
```

## DAYOFYEAR

指定された日付部分の年内の日を返します。

**構文**

```bash theme={null}
DAYOFYEAR(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT DAYOFYEAR('04/15/2000');
-- Result: 106
```

## EOMONTH

指定された日付を含む月の最終日を、オプションのオフセットとともに返します。

**構文**

```bash theme={null}
EOMONTH(date [, integer_month_to_add ]) or LAST_DAY(date)
```

**パラメータ**

* **date** 月の最終日を返す対象の日付を指定する datetime 式。
* **integer\_month\_to\_add** 月末を計算する前に日付に加算する月数を指定するオプションの整数式。

**例**

```bash theme={null}
SELECT EOMONTH('2018-02-01');
-- Result: 2018-02-28

SELECT LAST_DAY('2018-02-01');
-- Result: 2018-02-28

SELECT EOMONTH('2018-02-01', 2);
-- Result: 2018-04-30
```

## FDMONTH

指定された日付部分の月の初日を返します。

**構文**

```bash theme={null}
FDMONTH(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT FDMONTH('02-08-2018');
-- Result: 2/1/2018
```

## FDQUARTER

指定された日付部分の四半期の初日を返します。

**構文**

```bash theme={null}
FDQUARTER(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT FDQUARTER('05-08-2018');
-- Result: 4/1/2018
```

## FDWEEK

指定された日付部分の週の初日を返します。

**構文**

```bash theme={null}
FDWEEK(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT FDWEEK('02-08-2018');
-- Result: 2/4/2018
```

## FILEMODIFIEDTIME

関連ファイルの「更新日時」に関連付けられたタイムスタンプを返します。

**構文**

```bash theme={null}
FILEMODIFIEDTIME(uri)
```

**パラメータ**

* **uri** ローカルファイルシステム上のファイルを指す絶対パス。

**例**

```bash theme={null}
SELECT FILEMODIFIEDTIME('C:/Documents/myfile.txt');
-- Result: 6/25/2019 10:06:58 AM
```

## FROM\_DAYS

1582-10-15 以降の日数（グレゴリオ暦に基づく）から導出された日付を返します。これは MYSQL の FROM\_DAYS 関数と同等です。

**構文**

```bash theme={null}
FROM_DAYS(datevalue)
```

**パラメータ**

* **datevalue** 1582-10-15 以降の日数を表す整数値。

**例**

```bash theme={null}
SELECT FROM_DAYS(736000);
-- Result: 2/6/2015
```

## GETDATE

データベースシステムの現在のタイムスタンプを datetime 値として返します。この値は CURRENT\_TIMESTAMP および SYSDATETIME と同じで、常にローカルタイムゾーンの値です。

**構文**

```bash theme={null}
GETDATE()
```

**例**

```bash theme={null}
SELECT GETDATE();
-- Result: 2018-02-01 03:04:05
```

## GETUTCDATE

データベースシステムの現在のタイムスタンプを UTC の datetime 値としてフォーマットして返します。この値は SYSUTCDATETIME と同じです。

**構文**

```bash theme={null}
GETUTCDATE()
```

**例**

```bash theme={null}
SELECT GETUTCDATE();
-- For example, if the local timezone is Eastern European Time (GMT+2)
-- Result: 2018-02-01 05:04:05
```

## HOUR

指定された datetime から時の部分を返します。

**構文**

```bash theme={null}
HOUR(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT HOUR('02-02-2020 11:30:00');
-- Result: 11
```

## ISDATE

値が有効な date、time、または datetime 値の場合は 1 を返し、そうでない場合は 0 を返します。

**構文**

```bash theme={null}
ISDATE(date, [date_format])
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。
* **date\_format** オプションの datetime フォーマット。

**例**

```bash theme={null}
SELECT ISDATE('2018-02-01', 'yyyy-MM-dd');
-- Result: 1

SELECT ISDATE('Not a date');
-- Result: 0
```

## L\_LAST\_N\_DAYS

現在の日を除く、過去 n 日間。

**構文**

```bash theme={null}
L_LAST_N_DAYS(n)
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = LAST_N_DAYS(3)
```

## L\_LAST\_N\_WEEKS

現在の週より n 週前に始まり、前週で終わる、各週のすべての日。

**構文**

```bash theme={null}
L_LAST_N_WEEKS(n)
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = LAST_N_WEEKS(3)
```

## L\_LAST\_WEEK

前週のすべての日。

**構文**

```bash theme={null}
L_LAST_WEEK()
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = L_LAST_WEEK()
```

## L\_NEXT\_N\_DAYS

現在の日を含む、今後 n 日間。

**構文**

```bash theme={null}
L_NEXT_N_DAYS(n)
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = NEXT_N_DAYS(3)
```

**Also available:**

* LAST/NEXT\_90\_DAYS

## L\_NEXT\_N\_WEEKS

翌週から始まり、n 週後で終わる、各週のすべての日。

**構文**

```bash theme={null}
L_NEXT_N_WEEKS(n)
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = NEXT_N_WEEKS(3)
```

**Also available:**

* LAST/NEXT\_N\_MONTHS(n)
* LAST/NEXT\_N\_QUARTERS(n)
* LAST/NEXT\_N\_YEARS(n)

## L\_NEXT\_WEEK

翌週のすべての日。

**構文**

```bash theme={null}
L_NEXT_WEEK()
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = NEXT_WEEK()
```

**Also available:**

* LAST/THIS/NEXT MONTH
* LAST/THIS/NEXT QUARTER
* LAST/THIS/NEXT YEAR

## L\_THIS\_WEEK

現在の週のすべての日。

**構文**

```bash theme={null}
L_THIS_WEEK()
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = THIS_WEEK()
```

## L\_TODAY

現在の日。

**構文**

```bash theme={null}
L_TODAY()
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = TODAY()
```

## L\_TOMORROW

翌日。

**構文**

```bash theme={null}
L_TOMORROW()
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = TOMORROW()
```

## L\_YESTERDAY

前日。

**構文**

```bash theme={null}
L_YESTERDAY()
```

**例**

```bash theme={null}
SELECT * FROM MyTable WHERE MyDateField = YESTERDAY()
```

## LAST\_MONTH

現在の日付のちょうど 1 ヶ月前に相当するタイムスタンプを返します。

**構文**

```bash theme={null}
LAST_MONTH()
```

**例**

```bash theme={null}
SELECT LAST_MONTH(); //Assume the date is 3/17/2020
-- Result: 2/17/2020
```

## LAST\_WEEK

現在の日付のちょうど 1 週間前に相当するタイムスタンプを返します。

**構文**

```bash theme={null}
LAST_WEEK()
```

**例**

```bash theme={null}
SELECT LAST_WEEK(); //Assume the date is 3/17/2020
-- Result: 3/10/2020
```

## LAST\_YEAR

現在の日付のちょうど 1 年前に相当するタイムスタンプを返します。

**構文**

```bash theme={null}
LAST_YEAR()
```

**例**

```bash theme={null}
SELECT LAST_YEAR(); //Assume the date is 3/17/2020
-- Result: 3/10/2019
```

## LDMONTH

指定された月の最終日を返します。

**構文**

```bash theme={null}
LDMONTH(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT LDMONTH('02-02-2020');
-- Result: 2/29/2020
```

## LDQUARTER

指定された四半期の最終日を返します。

**構文**

```bash theme={null}
LDQUARTER(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT LDQUARTER('02-02-2020');
-- Result: 3/31/2020
```

## LDWEEK

指定された週の最終日を返します。

**構文**

```bash theme={null}
LDWEEK(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT LDWEEK('02-02-2020');
-- Result: 2/8/2020
```

## MAKEDATE

年と日数から日付値を返します。

**構文**

```bash theme={null}
MAKEDATE(year, days)
```

**パラメータ**

* **year** 年
* **days** 年内の日数。値は 0 より大きくする必要があります。

**例**

```bash theme={null}
SELECT MAKEDATE(2020, 1);
-- Result: 2020-01-01
```

## MINUTE

指定された datetime から分の部分を返します。

**構文**

```bash theme={null}
MINUTE(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT MINUTE('02-02-2020 11:15:00');
-- Result: 15
```

## MONTH

指定された datetime から月の部分を返します。

**構文**

```bash theme={null}
MONTH(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT MONTH('02-02-2020');
-- Result: 2
```

## QUARTER

指定された datetime に関連付けられた四半期を返します。

**構文**

```bash theme={null}
QUARTER(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT QUARTER('02-02-2020');
-- Result: 1
```

## SECOND

指定された datetime から秒の部分を返します。

**構文**

```bash theme={null}
SECOND(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT SECOND('02-02-2020 11:15:23');
-- Result: 23
```

## SMALLDATETIMEFROMPARTS

指定された日付と時刻の datetime 値を返します。

**構文**

```bash theme={null}
SMALLDATETIMEFROMPARTS(integer_year, integer_month, integer_day, integer_hour, integer_minute)
```

**パラメータ**

* **year** 年を指定する整数式。
* **month** 月を指定する整数式。
* **day** 日を指定する整数式。
* **hour** 時を指定する整数式。
* **minute** 分を指定する整数式。

**例**

```bash theme={null}
SELECT SMALLDATETIMEFROMPARTS(2018, 2, 1, 1, 2);
-- Result: 2018-02-01 01:02:00
```

## STRTODATE

指定された文字列値を解析し、対応する datetime を返します。

**構文**

```bash theme={null}
STRTODATE(string,format)
```

**パラメータ**

* **string** datetime 形式に変換する文字列値。
* **format** 最初の文字列入力の解釈方法を記述するフォーマット文字列。標準の [.NET 日付フォーマット構文](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) に従います。UNIX、UNIXMILIS、TICKS、および FILETICKS などの特殊なフォーマットも利用可能です。

**例**

```bash theme={null}
SELECT STRTODATE('03*04*2020','dd*MM*yyyy');
-- Result: 4/3/2020
```

## SYSDATETIME

データベースシステムの現在のタイムスタンプを datetime 値として返します。これは GETDATE および CURRENT\_TIMESTAMP と同じで、常にローカルタイムゾーンの値です。

**構文**

```bash theme={null}
SYSDATETIME()
```

**例**

```bash theme={null}
SELECT SYSDATETIME();
-- Result: 2018-02-01 03:04:05
```

## SYSUTCDATETIME

現在のシステムの日付と時刻を UTC の datetime 値として返します。これは GETUTCDATE と同じです。

**構文**

```bash theme={null}
SYSUTCDATETIME()
```

**例**

```bash theme={null}
SELECT SYSUTCDATETIME();
-- For example, if the local timezone is Eastern European Time (GMT+2)
-- Result: 2018-02-01 05:04:05
```

## TIMEFROMPARTS

指定された時刻と指定された精度の time 値を返します。

**構文**

```bash theme={null}
TIMEFROMPARTS(integer_hour, integer_minute, integer_seconds, integer_fractions, integer_precision)
```

**パラメータ**

* **hour** 時を指定する整数式。
* **minute** 分を指定する整数式。
* **seconds** 秒を指定する整数式。
* **fractions** 秒の小数部を指定する整数式。
* **precision** 小数部の精度を指定する整数式。

**例**

```bash theme={null}
SELECT TIMEFROMPARTS(1, 2, 3, 456, 3);
-- Result: 01:02:03.456
```

## TO\_DAYS

1582-10-15 以降の日数（グレゴリオ暦に基づく）を返します。これは MYSQL の TO\_DAYS 関数と同等です。

**構文**

```bash theme={null}
TO_DAYS(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT TO_DAYS('02-06-2015');
-- Result: 736000
```

## WEEK

指定された datetime に関連付けられた（年内の）週を返します。

**構文**

```bash theme={null}
WEEK(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT WEEK('02-17-2020 11:15:23');
-- Result: 8
```

## YEAR

指定された日付の年を指定する整数を返します。

**構文**

```bash theme={null}
YEAR(date)
```

**パラメータ**

* **date** 日付を指定する datetime 文字列。

**例**

```bash theme={null}
SELECT YEAR('2018-02-01');
-- Result: 2018
```
