w3resource

MySQL DAYOFMONTH() function

DAYOFMONTH() function

MySQL DAYOFMONTH() returns the day of the month for a given date. The day returned will be within the range of 1 to 31. If the date is ‘0000-00-00’, the function will return 0. The DAY() is the synonym of DAYOFMONTH().

This function is useful in -

  • By using DAYOFMONTH(), you can filter and query data based on specific days of the month, which is useful for tasks like analyzing events or trends occurring on certain days.
  • When entering or manipulating date data, DAYOFMONTH() helps users work with and validate the numeric day component.
  • In calculations that involve the day component of dates, such as calculating the number of days left until a specific day, DAYOFMONTH() is essential.
  • DAYOFMONTH() can be used to transform dates into a simplified numeric representation, which is useful for certain types of calculations.
  • When plotting data on charts or graphs, DAYOFMONTH() can be used to label data points with the numeric day of the month.
  • DAYOFMONTH() is used to identify the numeric day of the month in date-based analyses, helping you understand patterns or trends occurring on specific days.

Syntax:

DAYOFMONTH(date1)

Where date1 is a date.

Syntax Diagram:

MySQL DAYOFMONTH() Function - Syntax Diagram

MySQL Version: 8.0


Pictorial Presentation:

Pictorial Presentation of MySQL DAYOFMONTH() function

Example: MySQL DAYOFMONTH() function

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

Code:

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

Output:

mysql> SELECT DAYOFMONTH('2008-05-15');
+--------------------------+
| DAYOFMONTH('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: DAYNAME()
Next: DAY OF WEEK()



Follow us on Facebook and Twitter for latest update.