What is DAY() in SQL?

The DAY() function returns the day of the month when given a date sent as a parameter.

Figure 1 shows a visual representation of the DAY() function.

Figure 1: Visual representation of DAY() function

Syntax

DAY(date)

Parameter

The DAY() function takes the date as a parameter.

The date must be in the format YYYY-MM-DD, or else this function returns NULL.

Return value

The DAY() function returns the day of the month from a date sent as a parameter.

  • This function returns 0 if the value of the day is equal to 0.
  • This function returns NULL if the specified day is not present in the month, i.e., a day greater than 31 is not present in any month.

Code

The following example shows how we can isolate the day of the month from the admission dates of students using the DAY() function.

Students

Student ID

Student Name

Student Admission Date

1

David

2000-07-14

2

Luiss

2002-08-16

3

Harvey

2005-04-23

4

Lucy

2010-01-30

5

Andrew

2011-10-01

SELECT *, DAY(studentAdmissionDate) as DAY
from Students;

Free Resources