DAYNAME() Examples – MySQL

You can use the DAYNAME() function in MySQL to return the weekday name from a date.

By “weekday name”, I mean a value like Monday or Sunday. For example, if you provide a date of 2018-01-07, the DAYNAME() function will return Sunday.

Syntax

The syntax goes like this:

DAYNAME(date)

Where date is the date value that you want the weekday name returned from.

Example

Here’s an example to demonstrate.

SELECT DAYNAME('2021-03-16') AS 'Result';

Result:

+---------+
| Result  |
+---------+
| Tuesday |
+---------+

A Database Example

Here’s an example of extracting the weekday name from a column when running a query against a database.

USE sakila;
SELECT
  payment_date AS 'Date/Time',
  DAYNAME(payment_date) AS 'Weekday Name'
FROM payment
WHERE payment_id = 1;

Result:

+---------------------+--------------+
| Date/Time           | Weekday Name |
+---------------------+--------------+
| 2005-05-25 11:30:37 | Wednesday    |
+---------------------+--------------+

Current Date/Time

Here’s an example of extracting the weekday name from the current date and time (which is returned using the NOW() function).

SELECT 
    NOW(),
    DAYNAME(NOW());

Result:

+---------------------+----------------+
| NOW()               | DAYNAME(NOW()) |
+---------------------+----------------+
| 2018-06-25 19:05:41 | Monday         |
+---------------------+----------------+

Another way to do this is to use the CURDATE() function, which returns only the date (but not the time).

SELECT 
    CURDATE(),
    DAYNAME(CURDATE());    

Result:

+------------+--------------------+
| CURDATE()  | DAYNAME(CURDATE()) |
+------------+--------------------+
| 2018-06-25 | Monday             |
+------------+--------------------+