MySQL DAY() Function

The DAY() function in MySQL extracts the day of the month from a date value. It's a very useful function for working with dates and performing date-based filtering or calculations.



DAY(): Definition and Usage

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

Syntax

Syntax

DAY(date)
      

Parameter Values

Parameter Description
date The date (or datetime) value from which to extract the day. This is required.

Examples

Extracting the Day from a Date

This example shows how to get the day of the month from June 15th, 2017.

Syntax

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

15
      

Extracting the Day from a Datetime

This demonstrates that DAY() works correctly with datetime values as well.

Syntax

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

15
      

Extracting the Day from Today's Date

This query gets the day of the current month.

Syntax

SELECT DAY(CURDATE());
      
Output

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