MySQL DAYNAME function 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 Dayname() Function in MySQL is as shown below:
DAYNAME(date or expression);
MySQL Dayname function Example
The below shown queries help you understand the use of this MySQL Day name function. Here, we are returning the weekday name or name of the weekday from the date expression, and the Date and time 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() function, and CURDATE() function. We also used the date in YYYYMMDD format.
SELECT NOW(), DAYNAME(NOW() + 2);
SELECT CURDATE(), DAYNAME(CURDATE() + 2);
In this Date Function example, we are trying to return the name of the weekday from an invalid date and zero date part. That’s why it returns NULL.
MySQL Dayname Example 3
In this instance, we show you how to use this MySQL Day name function on a table. Here, we are returning the Weekday name of a Hire Date column. For this MySQL Dayname function demo, we are using Workbench to write a query against the customer table.
FROM `MySQL Tutorial`.customer;