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.



Where date is a date.

Syntax Diagram:

MySQL DAY() Function - Syntax Diagram

MySQL Version: 8.0

Pictorial Presentation:

Pictorial Presentation of MySQL DAY() function

Example: MySQL DAY() function

The following statement will return the day of the month from the specified date 2008-05-15.


SELECT DAY('2008-05-15');


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()

Follow us on Facebook and Twitter for latest update.