Declaration
WEEK(date[,mode])
Description
Returns the position of a week specified by the date or datetime type in a year.
The mode parameter specifies the logic for determining the number of weeks. Its possible values and meanings are listed in the following table.
Value |
The first day of the week |
Scope |
Meaning |
|---|---|---|---|
| 0 | Sunday | 0~53 | The weekly journal of the first Sunday is considered the first week of the year. |
| 1 | Monday | 0~53 | A weekly report that spans four or more days is considered the first week of the year. |
| 2 | Sunday | 1~53 | The weekly journal of the first Sunday is considered the first week of the year. |
| 3 | Monday | 1~53 | A weekly report that spans four or more days is considered the first week of the year. |
| 4 | Sunday | 0~53 | A weekly report that spans four or more days is considered the first week of the year. |
| 5 | Monday | 0~53 | The weekly report for the first Monday is considered the first week of the year. |
| 6 | Sunday | 1~53 | A weekly report that spans four or more days is considered the first week of the year. |
| 7 | Monday | 1~53 | The weekly report for the first Monday is considered the first week of the year. |
Note
If the specified date is the first day of the year, this function may return the last week of the previous year.
Examples
obclient> SELECT WEEK('2021-01-01',0);
+----------------------+
| WEEK('2021-01-01',0) |
+----------------------+
| 0 |
+----------------------+
1 row in set