MariaDB DAYOFWEEK() Function
The MariaDB DAYOFWEEK() function returns the weekday index of a given date or datetime value where 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday.
Syntax
DAYOFWEEK(datetime)
Parameters
datetime |
Required. Specify a date or datetime value from which to extract the weekday index. |
Return Value
Returns the weekday index of a given date or datetime value.
Return Value
Returns the weekday name of a given date or datetime value.
Example 1:
The example below shows the usage of DAYOFWEEK() function.
SELECT DAYOFWEEK('2018-08-18'); Result: 7 SELECT DAYOFWEEK('2018-08-18 10:38:42'); Result: 7 SELECT DAYOFWEEK('2018-08-18 10:38:42.000004'); Result: 7 SELECT DAYOFWEEK('2014-10-20'); Result: 2 SELECT DAYOFWEEK(CURDATE()); Result: 4
Example 2:
Consider a database table called Orders with the following records:
OrderQuantity | Price | OrderTime |
---|---|---|
100 | 1.58 | 2017-08-18 10:38:42 |
120 | 1.61 | 2018-03-23 07:14:16 |
125 | 1.78 | 2018-09-12 05:25:56 |
50 | 1.80 | 2019-01-16 11:52:05 |
200 | 1.72 | 2020-02-06 09:31:34 |
The statement given below can be used to get the weekday index of records of column OrderTime:
SELECT *, DAYOFWEEK(OrderTime) AS DAYOFWEEK_Value FROM Orders;
This will produce the result as shown below:
OrderQuantity | Price | OrderTime | DAYOFWEEK_Value |
---|---|---|---|
100 | 1.58 | 2017-08-18 10:38:42 | 6 |
120 | 1.61 | 2018-03-23 07:14:16 | 6 |
125 | 1.78 | 2018-09-12 05:25:56 | 4 |
50 | 1.80 | 2019-01-16 11:52:05 | 4 |
200 | 1.72 | 2020-02-06 09:31:34 | 5 |
❮ MariaDB Functions