What is DAYOFWEEK() in SQL?
The DAYOFWEEK() function returns the weekday index from a date sent as a parameter.
Figure 1 shows a visual representation of the DAYOFWEEK() function and the week index.
Syntax
DAYOFWEEK(date)
Parameter
The DAYOFWEEK() function takes the date as a parameter.
The date must be in the format YYYY-MM-DD, or else this function returns
NULL.
Return value
The DAYOFWEEK() function returns the week index from a date sent as a parameter.
It returns
NULLif the date is invalid.
Code
-- current dateSELECT DAYOFWEEK(NOW());-- invalid monthSELECT DAYOFWEEK('2021-0-12');-- valid month/daySELECT DAYOFWEEK('2021-05-03');-- invalid daySELECT DAYOFWEEK('2021-2-30');