MySQL DAY() function
MySQL DAY() returns the day of the month for a specified date. The day returned will be within the range of 1 to 31. If the given date is ‘0000-00-00’, the function will return 0. The DAYOFMONTH() is the synonym of DAY().
This function is useful in -
- When aggregating data by day, such as calculating the average daily sales, the DAY() function helps group data and perform calculations accurately.
- DAY() is used to identify the day of the month in date-based analyses, helping you understand patterns or trends occurring on specific days.
- For presenting dates in custom formats, DAY() helps extract the day component to incorporate into formatted date strings.
- In financial applications, DAY() aids in scheduling payments by extracting the payment day from a date, ensuring timely transactions.
- When labeling data points on charts, DAY() helps provide a concise representation of the day component of the date.
- For planning events, promotions, or campaigns that occur on certain days of the month, DAY() helps identify suitable dates.
Where date is a date.
MySQL Version: 8.0
Example: MySQL DAY() function
The following statement will return the day of the month from the specified date 2008-05-15.
mysql> SELECT DAY('2008-05-15'); +-------------------+ | DAY('2008-05-15') | +-------------------+ | 15 | +-------------------+ 1 row in set (0.00 sec)
All Date and Time Functions :
Click here to see the MySQL Date and time functions.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook