MySQL WEEKDAY function is a Date Function, which is used to return the weekday value of a given date. This function returns value range from 1 to 6 where 0 = Sunday, 1 = Monday, 2 = Tuesday, ….. 6 = Sunday.
In this article, we will show you, How to use this WEEKDAY function to get the Weekday in MySQL from an expression with example.
MySQL WEEKDAY Syntax
The basic syntax of the WEEKDAY() Function in MySQL is as shown below:
WEEKDAY(date or expression);
MySQL WEEKDAY function Example
These examples helps you understand the basic use of 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.
MySQL WEEKDAY Function Example 2
The following query will show you, what happens when we try to find the weekday from 0 date format, or invalid dates.
From the above 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.
Thank You for Visiting Our Blog