Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

mysql
sql
day
communitycreator

What is DAY() in SQL?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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;

RELATED TAGS

mysql
sql
day
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring