MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB WEEKDAY() Function



The MariaDB WEEKDAY() function returns the weekday index of a given date or datetime value where 0=Monday, 1=Tuesday, 2=Wednesday, 3=Thursday, 4=Friday, 5=Saturday, 6=Sunday.

Syntax

WEEKDAY(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.

Example 1:

The example below shows the usage of WEEKDAY() function.

SELECT WEEKDAY('2018-08-18');
Result: 5

SELECT WEEKDAY('2018-08-18 10:38:42');
Result: 5

SELECT WEEKDAY('2018-08-18 10:38:42.000004');
Result: 5

SELECT WEEKDAY('2014-10-20');
Result: 0

SELECT WEEKDAY(CURDATE());
Result: 2

Example 2:

Consider a database table called Orders with the following records:

OrderQuantityPriceOrderTime
1001.582017-08-18 10:38:42
1201.612018-03-23 07:14:16
1251.782018-09-12 05:25:56
501.802019-01-16 11:52:05
2001.722020-02-06 09:31:34

The statement given below can be used to get the weekday index of records of column OrderTime:

SELECT *, WEEKDAY(OrderTime) AS WEEKDAY_Value FROM Orders;

This will produce the result as shown below:

OrderQuantityPriceOrderTimeWEEKDAY_Value
1001.582017-08-18 10:38:424
1201.612018-03-23 07:14:164
1251.782018-09-12 05:25:562
501.802019-01-16 11:52:052
2001.722020-02-06 09:31:343

❮ MariaDB Functions