Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql
mysql
dayofmonth
communitycreator

What is DAYOFMONTH() 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 DAYOFMONTH() function returns what day of the month it is from a date sent as a parameter.

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

Figure 1: Visual representation of DAYOFMONTH() function

Syntax

DAYOFMONTH(date)

Parameter

The DAYOFMONTH() 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 DAYOFMONTH() function returns the day of the month from a date sent as a parameter.

It returns NULL if the date is invalid.

Code

-- current date
SELECT DAYOFMONTH(NOW());
-- invalid month
SELECT DAYOFMONTH('2021-13-12');
-- valid month/day
SELECT DAYOFMONTH('2021-05-03');
-- invalid day
SELECT DAYOFMONTH('2021-2-30');

RELATED TAGS

sql
mysql
dayofmonth
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