WEEKDAY() vs DAYOFWEEK() in MariaDB: What’s the Difference?

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:

FunctionIndexing
WEEKDAY()0 = Monday
1 = Tuesday
2 = Wednesday
3 = Thursday
4 = Friday
5 = Saturday
6 = Sunday
DAYOFWEEK()Uses ODBC indexing, which is:
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = 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.