Open In App

Use of DAYOFWEEK() function in MySQL

DAYOFWEEK() :
This function in MySQL helps to return weekday numbers/index from the given date(a number from 1 to 7). The weekday index returned by DAYOFWEEK() function follows ODBC standards.

Note –
Following are the weekday numbers.



Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

Syntax :

DAYOFWEEK(date)

Parameters :
The function accepts only one argument.



Returns :

Example-1 :
Obtaining the day of the week from a specific date “2020-09-13”.

SELECT DAYOFWEEK("2020-09-13") 
AS WEEKDAY;

Output :

WEEKDAY
1

Example-2 :
Obtaining the day of the week from a specific DateTime “2000-11-27 07:12:23”.

SELECT DAYOFWEEK("2000-11-02 07:12:23") 
AS WEEKDAY;

Output :

WEEKDAY
5

Example-3 :
Obtaining the day of the week for the current system date i.e using CURDATE() function

SELECT DAYOFWEEK(CURDATE()) 
AS WEEKDAY;

Output :

WEEKDAY
4
Article Tags :
SQL