MySQL WEEKDAY Function

MySQL WEEKDAY is one of the Date Functions, which returns the weekday value of a given date. This weekday function returns value range from 1 to 6 where 0 = Sunday, 1 = Monday, 2 = Tuesday, ….. 6 = Sunday, and the syntax of it is as shown below:

WEEKDAY(date or expression);

MySQL WEEKDAY function Example

These examples help you understand the basic use of the method. Here, we are returning the Week day number from the date expression and the Datetime expression.

SELECT WEEKDAY('2015-02-10');

SELECT WEEKDAY('2018-05-22 01:09:22');

SELECT WEEKDAY('2018-05-26 01:09:22');
MySQL WEEKDAY Function 3

Let us see another example of the WEEKDAY function. Here, we are returning the Week day from the current datetime returned by the Now().

SELECT WEEKDAY(NOW());

SELECT WEEKDAY(NOW()+2);
WEEK DAY Example 4

The following MySQL query shows you what happens when we try to find the week day from 0 date format or invalid dates.

SELECT WEEKDAY(0);

SELECT WEEKDAY('2019-14-25');
WEEK DAY Example 5

From the above Date Function screenshot, (0) means we are trying to extract week day from a zero date part. That’s why it returns NULL. Within the Last statement, (‘2019-14-25’); was returned NULL. Because it is an invalid dt.