MySQL DAY() Function
MySQL DAY(): Extract the Day Number of the Month
The DAY() function returns the day of the month as an integer from 1 to 31 for a given DATE or DATETIME value. It is a concise synonym for DAYOFMONTH().
Billing scripts and payroll jobs use DAY() to group customers by billing cycle day or check whether an event occurred on the first of the month.
Syntax
Pass any date or timestamp expression to DAY():
DAY(date_value)
date_value: ADATE,DATETIME,TIMESTAMP, or valid date string.
The function returns an integer from 1 to 31 for normal dates, 0 when the day part is zero (if non-strict mode permits '2026-05-00'), or NULL for invalid inputs.
Practical Example
Suppose your billing service groups accounts in demo_customers by their monthly invoice day based on signup_date.
SELECT
customer_id,
full_name,
signup_date,
DAY(signup_date) AS billing_day
FROM demo_customers
WHERE customer_id IN (401, 405, 408);
| customer_id | full_name | signup_date | billing_day |
|---|---|---|---|
| 401 | Amina Chowdhury | 2026-05-10 | 10 |
| 405 | Maya Lin | 2026-01-31 | 31 |
| 408 | David Kim | 2026-02-01 | 1 |
Using DAY() gives you a clean integer you can compare with > or < without converting formatted strings.
Common Mistakes & NULL Behavior
Avoid these common misunderstandings with DAY():
NULLand impossible dates returnNULL:DAY(NULL)andDAY('2026-04-31')both evaluate toNULL.- Returns day of month, not weekday:
DAY('2026-05-12')returns12, not2or'Tuesday'. UseDAYOFWEEK(),WEEKDAY(), orDAYNAME()for weekday values. - Watch out for day
31billing logic: Customers withbilling_day = 31will not matchDAY(CURDATE()) = 31in 30-day months or February. UseLAST_DAY()checks for end-of-month billing. - No
TIME-only strings: Passing'14:20:00'without a date causesDAY()to returnNULL.
Frequently Asked Questions
Is there any difference between DAY() and DAYOFMONTH()?
No. DAY() is a direct synonym for DAYOFMONTH(). Both return the exact same integer value (1..31).
Does DAY() return zero-padded values like '05'?
No. DAY() returns an integer (5), whereas DATE_FORMAT(date_col, '%d') returns a zero-padded two-character string ('05').
Can DAY() extract the day from a DATETIME string?
Yes. DAY('2026-05-04 19:30:00') ignores the time portion and returns 4.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.