MySQL DAYNAME is one of the Date Functions, which returns the name of the weekday from a given date. For example, Monday, Tuesday, etc. The basic syntax of the MySQL Dayname Function is as shown below:
DAYNAME(date or expression);
MySQL Dayname function Example
The below shown queries help you understand the use of this Day name function. Here, we are returning the weekday name or name of the weekday from the date expression, and the Datetime expression.
SELECT DAYNAME('2019-03-04 10:22:59');
SELECT NOW(), DAYNAME(NOW());
MySQL Dayname Function Example 2
The following MySQL query shows you what happens when we try to return the weekday name from a date in string format. Here, we are returning the name of the weekday from the current date and time returned by the Now(), and CURDATE(). We also used the dt in YYYYMMDD format.
SELECT NOW(), DAYNAME(NOW() + 2);
SELECT CURDATE(), DAYNAME(CURDATE() + 2);
In this Date method example, we are trying to return the name of the weekday from an invalid and zero date part. That’s why it returns NULL.
Dayname Example 3
In this instance, we show you how to use this MySQL Dayname function on a table. Here, we are returning the Weekday name of a HireDate column. For this demo, we are using Workbench to write a query against the customer table.
SELECT EmpID, FirstName, LastName, Occupation, YearlyIncome, Sales, HireDate, DAYNAME(HireDate) FROM customer;