Declaration
YEARWEEK(date[,mode])
Description
Returns the year of a date or datetime type date, as well as the week number of the year.
The mode parameter determines the logic for calculating the week number. 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 YEARWEEK('2021-01-01');
+------------------------+
| YEARWEEK('2021-01-01') |
+------------------------+
| 202052 |
+------------------------+
1 row in set