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.
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
0if the value of the day is equal to 0.- This function returns
NULLif 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 DAYfrom Students;