SQL Server DAY() Function

The DAY() function in SQL Server 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 filtering, calculations, or reporting.



DAY(): Definition and Usage

DAY() takes a date or datetime value and returns an integer representing the day of the month (a number between 1 and 31). This is helpful for various data manipulation and analysis tasks involving dates.

Syntax

Syntax

DAY(date)
      

Parameter Values

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

Examples

Extracting the Day from a Date

This example extracts the day (25) from the date '2017/08/25'.

Syntax

SELECT DAY('2017/08/25') AS DayOfMonth;
      
Output

DayOfMonth
-----------
25
      

Extracting the Day from a DateTime

This example shows that DAY() works correctly with datetime values; it ignores the time portion and returns only the day of the month.

Syntax

SELECT DAY('2017/08/13 09:08') AS DayOfMonth;
      
Output

DayOfMonth
-----------
13