VeloDB Cloud
SQL Manual
Functions
date-time-functions
week

week

Description

Syntax:

INT WEEK(DATE date) INT WEEK(DATE date, INT mode)

This function returns the week number of the given date.The default value of mode is 0. The following table describes how the mode argument works.

ModeFirst day of weekRangeDefinition of the first week
0Sunday0-53The week containing the first Sunday of the year
1Monday0-53The first week in the year that no less than 4 days of the week belongs to the year
2Sunday1-53The week containing the first Sunday of the year
3Monday1-53The first week in the year that no less than 4 days of the week belongs to the year
4Sunday0-53The first week in the year that no less than 4 days of the week belongs to the year
5Monday0-53The week containing the first Monday of the year
6Sunday1-53The first week in the year that no less than 4 days of the week belongs to the year
7Monday1-53The week containing the first Monday of the year

The parameter is of DATE or DATETIME type.

Example

mysql> select week('2020-1-1');
+------------------+
| week('2020-1-1') |
+------------------+
|                0 |
+------------------+
mysql> select week('2020-7-1',1);
+---------------------+
| week('2020-7-1', 1) |
+---------------------+
|                  27 |
+---------------------+

Keywords

WEEK