MySQL WEEK()
MySQL 날짜함수, 시간함수
WEEK()
-
WEEK(date[, mode])
의 형태
This function returns the week number for date. The two-argument form of WEEK() enables you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or 1 to 53. If the mode argument is omitted, the value of the default_week_format system variable is used.
The following table describes how the mode argument works.
| Mode | First day of week | Range | Week 1 is the first week... |
| 0 | Sunday | 0-53 | with a Sunday in this year |
| 1 | Monday | 0-53 | with 4 or more days days this year |
| 2 | Sunday | 1-53 | with a Sunday in this year |
| 3 | Monday | 1-53 | with 4 or more days this year |
| 4 | Sunday | 0-53 | with 4 or more days this year |
| 5 | Monday | 0-53 | with a Monday in this year |
| 6 | Sunday | 1-53 | with 4 or more days this ear |
| 7 | Monday | 1-53 | with a Monday in this year |
For mode values with a meaning of "with 4 mor more days this year", weeks are numbered according to ISO 8601:1988:
- It the week containing January 1 has 4 or more days in the new year, it is week 1.
- Otherwise, it is the last week of the previous year, and the next week is week 1.
mysql> SELECT WEEK(NOW());
+-------------+
| WEEK(NOW()) |
+-------------+
| 14 |
+-------------+
1 row in set (0.00 sec)
mysql> SELECT WEEK('2020-04-01');
+--------------------+
| WEEK('2020-04-01') |
+--------------------+
| 13 |
+--------------------+
1 row in set (0.00 sec)
mysql> SELECT WEEK('2020-04-01', 0);
+-----------------------+
| WEEK('2020-04-01', 0) |
+-----------------------+
| 13 |
+-----------------------+
1 row in set (0.00 sec)
mysql> SELECT WEEK('2020-04-01', 1);
+-----------------------+
| WEEK('2020-04-01', 1) |
+-----------------------+
| 14 |
+-----------------------+
1 row in set (0.00 sec)