MySQL DAYNAME() Function

The DAYNAME() function in MySQL returns the full name of the weekday for a given date or datetime value. The result is the name of the weekday (e.g., "Monday", "Tuesday", etc.).


Definition and Usage

  • The DAYNAME() function returns the weekday name for the specified date.
  • The returned name will be in full (e.g., "Sunday", "Monday").

Syntax

DAYNAME(date)
  • date: Required. A valid date or datetime value for which the weekday name is to be extracted.

Examples

Example 1: Return the weekday name for a specific date

SELECT DAYNAME("2017-06-15");

Output:

Thursday

This query returns Thursday as it is the weekday for the date 2017-06-15.

Example 2: Return the weekday name for a datetime value

SELECT DAYNAME("2017-06-15 09:34:21");

Output:

Thursday

Even though the datetime contains both date and time, the DAYNAME() function returns only the full weekday name (Thursday).

Example 3: Return the weekday name for the current system date

SELECT DAYNAME(CURDATE());

Output:

Friday

Assuming today's date is 2024-12-28, this query will return Friday as it is the current weekday.


Use Cases

  • Extracting Day of the Week: Useful when you need to get the name of the weekday (e.g., "Monday", "Tuesday").
  • Reports and Analysis: You can use DAYNAME() to categorize or filter data based on weekdays in reports.
  • Scheduling: Helpful in applications that require weekday names to be displayed.

Related Functions

  • DAY(): Returns the day of the month.
  • DAYOFWEEK(): Returns the weekday index (1 for Sunday through 7 for Saturday).
  • DAYOFYEAR(): Returns the day of the year (1 through 366).
  • MONTHNAME(): Returns the full name of the month for a given date.

Was this article helpful?