TutorialsArena

MySQL DAYOFMONTH() Function

The DAYOFMONTH() function in MySQL extracts the day of the month from a date value. It's a simple but very useful function for working with dates and performing date-based operations.



DAYOFMONTH(): Definition and Usage

DAYOFMONTH() takes a date or datetime value as input and returns an integer representing the day of the month. The returned value will always be between 1 and 31 (inclusive). This function is functionally equivalent to the DAY() function.

Syntax

Syntax

DAYOFMONTH(date)
      

Parameter Values

Parameter Description
date The date or datetime value. This is required.

Examples

Extracting the Day of the Month from a Date

This example extracts the day (15) from the date "2017-06-15".

Syntax

SELECT DAYOFMONTH("2017-06-15");
      
Output

15
      

Extracting the Day of the Month from a DateTime

This shows that DAYOFMONTH() works correctly with datetime values.

Syntax

SELECT DAYOFMONTH("2017-06-15 09:34:21");
      
Output

15
      

Extracting Today's Day of the Month

This retrieves the current day of the month.

Syntax

SELECT DAYOFMONTH(CURDATE());
      
Output

(The current day of the month, a number between 1 and 31)