MariaDB WEEK() Function
The MariaDB WEEK() function returns week portion of a given date or datetime value. It can be between 0-53 or 1-53 depending on the specified mode.
The WEEKOFYEAR() function returns the same as the WEEK() function with the syntax of WEEK(datetime, 3).
mode and description
|0||First day of the week is Sunday||0-53|
|1||First day of the week is Monday and the first week has more than 3 days||0-53|
|2||First day of the week is Sunday||1-53|
|3||First day of the week is Monday and the first week has more than 3 days||1-53|
|4||First day of the week is Sunday and the first week has more than 3 days||0-53|
|5||First day of the week is Monday||0-53|
|6||First day of the week is Sunday and the first week has more than 3 days||1-53|
|7||First day of the week is Monday||1-53|
Returns the week portion of a given date or datetime value.
The example below shows the usage of WEEK() function.
SELECT WEEK('2018-08-18'); Result: 32 SELECT WEEK('2018-08-18 10:38:42'); Result: 32 SELECT WEEK('2018-08-18 10:38:42.000004'); Result: 32 SELECT WEEK('2014-10-25'); Result: 42 SELECT WEEK(CURDATE()); Result: 48
Consider a database table called Orders with the following records:
The query given below can be used to get the week portion of records of column OrderTime:
SELECT *, WEEK(OrderTime, 5) AS WEEK_Value FROM Orders;
This will produce the result as shown below:
❮ MariaDB Functions