EN
MySQL - WEEKDAY() and DAYOFWEEK() differences
0
points
In this article, we would like to show you differences between WEEKDAY()
and DAYOFWEEK()
functions in MySQL.
WEEKDAY()
function
The WEEKDAY()
function counts days of the week from Monday
and starts from 0
.
Example:
0 = Monday
1 = Tuesday
2 = Wednesday
3 = Thursday
4 = Friday
5 = Saturday
6 = Sunday
DAYOFWEEK()
function
The DAYOFWEEK()
function counts days of the week from Sunday
and starts from 1
.
Example:
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday
Practical example
In this example, we will select the current day of the week and display its number using WEEKDAY()
and DAYOFWEEK()
functions.
Query:
SELECT WEEKDAY(NOW()) 'weekday', DAYOFWEEK(NOW()) 'dayofweek';
Example result for Monday: