MySQL DAY() function
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.
Syntax:
DAY(date)
Where date is a date.
Syntax Diagram:
MySQL Version: 8.0
Pictorial Presentation:
Example: MySQL DAY() function
The following statement will return the day of the month from the specified date 2008-05-15.
Code:
SELECT DAY('2008-05-15');
Output:
mysql> SELECT DAY('2008-05-15'); +-------------------+ | DAY('2008-05-15') | +-------------------+ | 15 | +-------------------+ 1 row in set (0.00 sec)
Video Presentation:
All Date and Time Functions :
Click here to see the MySQL Date and time functions.
Previous: DATEDIFF()
Next: DAYNAME()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/date-and-time-functions/mysql-day-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics