The DAYNAME() function in MySQL is used to return the name of the day (e.g., 'Sunday', 'Monday', etc.) for a given date.
Syntax:
DAYNAME(date)
Parameters:
- date: The date value you want the day name for. It must be in a valid date format.
Example Usage:
-
Basic Example:
SELECT DAYNAME('2024-12-25') AS DayName;Result:
DayName ------- Wednesday -
From a Table: Suppose you have a table
eventswith a columnevent_date:SELECT event_date, DAYNAME(event_date) AS DayName FROM events; -
Current Date: You can use
CURDATE()to get the current date:SELECT DAYNAME(CURDATE()) AS DayName;
Use Cases:
- Useful for generating reports based on the day of the week.
- Organizing or grouping data by day names in queries.
Let me know if you need more examples!
No comments:
Post a Comment