MariaDB provides a WEEKDAY()
function and a DAYOFWEEK()
function, both of which return the day of the week, represented as a number.
But the number returned is different between these functions.
This post looks at the difference.
The Difference
The following table highlights the difference between these two functions:
Function | Indexing |
---|---|
WEEKDAY() | 0 = Monday1 = Tuesday2 = Wednesday3 = Thursday4 = Friday5 = Saturday6 = Sunday |
DAYOFWEEK() | Uses ODBC indexing, which is:1 = Sunday2 = Monday3 = Tuesday4 = Wednesday5 = Thursday6 = Friday7 = Saturday |
Example
Here’s an example with each function side by side:
SELECT
DAYOFWEEK('2030-01-20') AS DAYOFWEEK,
WEEKDAY('2030-01-20') AS WEEKDAY,
DAYNAME('2030-01-20') AS DAYNAME;
Result:
+-----------+---------+---------+ | DAYOFWEEK | WEEKDAY | DAYNAME | +-----------+---------+---------+ | 1 | 6 | Sunday | +-----------+---------+---------+
We can see that each function returned a different number, even though it was for the same day.
Here, we also used DAYNAME()
to return the actual name of the day.