メインコンテンツまでスキップ
バージョン: 4.x

YEARWEEK

yearweek

説明

構文

INT YEARWEEK(DATE date[, INT mode])

日付の年と週を返します。mode引数の値はデフォルトで0です。 日付の週が前年に属する場合は前年の年と週が返され、日付の週が翌年に属する場合は翌年の年が返され週は1になります。

以下の表はmode引数の動作を説明します。

Mode週の最初の日範囲週1は最初の週…
0Sunday1-53with a Sunday in this year
1Monday1-53with 4 or more days this year
2Sunday1-53with a Sunday in this year
3Monday1-53with 4 or more days this year
4Sunday1-53with 4 or more days this year
5Monday1-53with a Monday in this year
6Sunday1-53with 4 or more days this year
7Monday1-53with a Monday in this year

パラメータはDateまたはDatetime型です

mysql> select yearweek('2021-1-1');
+----------------------+
| yearweek('2021-1-1') |
+----------------------+
| 202052 |
+----------------------+
mysql> select yearweek('2020-7-1');
+----------------------+
| yearweek('2020-7-1') |
+----------------------+
| 202026 |
+----------------------+
mysql> select yearweek('2024-12-30',1);
+------------------------------------+
| yearweek('2024-12-30 00:00:00', 1) |
+------------------------------------+
| 202501 |
+------------------------------------+

keywords

YEARWEEK
このページでは