totn MariaDB Functions

MariaDB: WEEK Function

This MariaDB tutorial explains how to use the MariaDB WEEK function with syntax and examples.

Description

The MariaDB WEEK function returns the week portion of a date value.

Syntax

The syntax for the WEEK function in MariaDB is:

WEEK( date_value, [ mode ] )

Parameters or Arguments

date_value
A date or datetime value from which to extract the week.
mode

Optional. It is used to specify what day the week starts on. It can be one of the following:

mode Explanation Returns
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

Note

Applies To

The WEEK function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB WEEK function examples and explore how to use the WEEK function in MariaDB.

For example:
(Note: Your results may vary from the examples below depending on what your default_week_format system variable is set to.)

SELECT WEEK('2014-01-01');
Result: 0

SELECT WEEK('2014-01-05');
Result: 1

SELECT WEEK('2014-01-12');
Result: 2

SELECT WEEK('2014-05-19');
Result: 20

SELECT WEEK('2014-11-23');
Result: 47

This last WEEK example would display the week portion of the current system date (current system date is returned by the CURDATE function).

SELECT WEEK(CURDATE());