MySQL WEEKDAY function is one of the Date Functions, which returns the weekday value of a given date. This MySQL weekday function returns value range from 1 to 6 where 0 = Sunday, 1 = Monday, 2 = Tuesday, ….. 6 = Sunday.
The syntax of the WEEKDAY() Function in MySQL is as shown below:
WEEKDAY(date or expression);
MySQL WEEKDAY function Example
These examples help you understand the basic use of the Weekday function. Here, we are returning the Weekday number from the date expression, and the Date and time expression.
SELECT WEEKDAY('2018-05-22 01:09:22');
SELECT WEEKDAY('2018-05-26 01:09:22');
Let us see another example of MySQL WEEKDAY function. Here, we are returning the Weekday from the current date and time returned by the Now() function.
WEEKDAY Function Example 2
The following MySQL query shows you what happens when we try to find the week day from 0 date format or invalid dates.
From the above Date Function screenshot, WEEKDAY(0) means, we are trying to extract weekday from a zero date part. That’s why it returns NULL.
Within the Last statement, WEEKDAY(‘2019-14-25’); was returned NULL. Because it is an invalid date.