MariaDB DAYOFWEEK() Function
In MariaDB, DAYOFWEEK() is a built-in function that returns a number representing the weekday for a given date.
MariaDB DAYOFWEEK() Syntax
This is the syntax of the MariaDB DAYOFWEEK() function:
DAYOFWEEK(expr)
Parameters
expr-
Required. A date or datetime expression.
If you provide no parameters or the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'DAYOFWEEK'.
Return value
The MariaDB DAYOFWEEK() function returns the index of the weekday for a given date. It returns a integer from 1 to 7, representing the following meanings:
1- Sunday2- Monday3- Tuesday4- Wednesday5- Thursday6- Friday7- Saturday
If the specified expression is not a valid date or datetime, the DAYOFWEEK() function will return NULL.
If the argument is NULL, the DAYOFWEEK() function will return NULL.
MariaDB DAYOFWEEK() Examples
Basic usage
SELECT
DAYOFWEEK('2022-02-21'),
DAYOFWEEK('2022-02-22'),
DAYOFWEEK('2022-02-23'),
DAYOFWEEK('2022-02-24'),
DAYOFWEEK('2022-02-25'),
DAYOFWEEK('2022-02-26'),
DAYOFWEEK('2022-02-27')\G
Output:
DAYOFWEEK('2022-02-21'): 2
DAYOFWEEK('2022-02-22'): 3
DAYOFWEEK('2022-02-23'): 4
DAYOFWEEK('2022-02-24'): 5
DAYOFWEEK('2022-02-25'): 6
DAYOFWEEK('2022-02-26'): 7
DAYOFWEEK('2022-02-27'): 1Invalid date
If the specified expression is not a valid date or datetime, the DAYOFWEEK() function will return NULL.
SELECT
DAYOFWEEK('2022-02-00'),
DAYOFWEEK('2022-02-30'),
DAYOFWEEK('Not A DATE')\G
Output:
DAYOFWEEK('2022-02-00'): NULL
DAYOFWEEK('2022-02-30'): NULL
DAYOFWEEK('Not A DATE'): NULLOther delimiters
The MariaDB DAYOFWEEK() function allow you to construct dates with various separators:
SELECT
DAYOFWEEK('2023/01/08'),
DAYOFWEEK('2023,01!08'),
DAYOFWEEK('2023#01%08');
Output:
+-------------------------+-------------------------+-------------------------+
| DAYOFWEEK('2023/01/08') | DAYOFWEEK('2023,01!08') | DAYOFWEEK('2023#01%08') |
+-------------------------+-------------------------+-------------------------+
| 1 | 1 | 1 |
+-------------------------+-------------------------+-------------------------+Conclusion
In MariaDB, DAYOFWEEK() is a built-in function that returns a number representing the weekday for a given date.