メインコンテンツまでスキップ

説明

DAY関数は、日付または時間の式から「日」の部分を抽出し、1から31の範囲(月と年に依存)の整数値を返すために使用されます。

この関数は、MySQLのday functionと一貫して動作します。

エイリアス

  • dayofmonth

構文

DAY(<date_or_time_expr>)

パラメータ

パラメータ説明
<date_or_time_expr>date/datetimeタイプをサポートする有効な日付式。具体的なdatetimeとdateの形式については、datetime conversiondate conversionを参照してください

戻り値

日付の「日」の整数情報(1-31)を返します。

特殊なケース:

dtがNULLの場合、NULLを返します;


--Extract day from DATE type
select day('1987-01-31');
+----------------------------+
| day('1987-01-31 00:00:00') |
+----------------------------+
| 31 |
+----------------------------+

---Extract day from DATETIME type (ignoring time part)
select day('2023-07-13 22:28:18');
+----------------------------+
| day('2023-07-13 22:28:18') |
+----------------------------+
| 13 |
+----------------------------+

---Input is NULL
select day(NULL);
+-----------+
| day(NULL) |
+-----------+
| NULL |
+-----------+