MySQL DAYNAME function is one of the Date Function, which is used to return the name of the weekday from a given date. For example, Monday, Tuesday etc.
In this article, we will show you, How to use this MySQL Dayname function to get the dayname from an expression with example.
MySQL Dayname Syntax
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 helps 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 query shows you, what happens when we try to return the weekday name from a date in string format.
SELECT NOW(), DAYNAME(NOW() + 2);
SELECT CURDATE(), DAYNAME(CURDATE() + 2);
Here, 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 example, we will 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;
Thank You for Visiting Our Blog