MySQL DAYNAME Function

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-05');

SELECT DAYNAME('2019-03-04 10:22:59');

SELECT NOW(), DAYNAME(NOW());
MySQL DAYNAME Function 1

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);

SELECT DAYNAME(20181231);
MySQL DAYNAME Function 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.

SELECT DAYNAME(2018-12-41);

SELECT DAYNAME(2018-00-00);

SELECT DAYNAME(0000-00-00);
MySQL DAYNAME Function 3

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.

SELECT EmpID,
FirstName,
LastName,
Occupation,
YearlyIncome,
Sales,
HireDate,
DAYNAME(HireDate)
FROM `MySQL Tutorial`.customer;
MySQL DAYNAME Function 4