Lesson

MySQL DATE_ADD() Function

10 min reading
Free Course

MySQL DATE_ADD(): Add Flexible Time Intervals to Dates

The DATE_ADD() function adds a time or calendar interval to a DATE or DATETIME value. It supports everything from microseconds to years, plus compound units like DAY_HOUR and YEAR_MONTH.

Subscription billing systems use DATE_ADD() to compute next renewal dates, grace periods, and annual contract expirations.

Syntax

DATE_ADD() always requires the INTERVAL keyword and a unit name:

DATE_ADD(date_value, INTERVAL expr unit)
  • date_value: A DATE, DATETIME, or valid date string.
  • expr: A numeric value (or formatted string for compound units like '1 06' for DAY_HOUR).
  • unit: MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, or compound units.

Practical Example

Suppose your SaaS billing query calculates monthly renewal dates and 14-day onboarding check-ins for rows in demo_customers.

SELECT
    customer_id,
    full_name,
    signup_date,
    DATE_ADD(signup_date, INTERVAL 14 DAY) AS onboarding_checkin,
    DATE_ADD(signup_date, INTERVAL 1 MONTH) AS next_renewal
FROM demo_customers
WHERE customer_id IN (405, 406, 407);
customer_id full_name signup_date onboarding_checkin next_renewal
405 Maya Lin 2026-01-31 2026-02-14 2026-02-28
406 Victor Gomez 2024-02-29 2024-03-14 2024-03-29
407 Sara Ahmed 2026-05-10 2026-05-24 2026-06-10

When adding INTERVAL 1 MONTH to 2026-01-31, MySQL clamps the day to 2026-02-28 so the result remains a valid calendar date.

Common Mistakes & NULL Behavior

Watch out for these issues when calling DATE_ADD():

  • No integer shorthand: Unlike ADDDATE(d, 5), writing DATE_ADD(d, 5) without INTERVAL 5 DAY raises a syntax error.
  • Invalid dates and NULL inputs return NULL: Passing '2026-02-30', '2026-00-00', or NULL as either the date or interval value makes DATE_ADD() return NULL.
  • Leap-year clamping: Adding INTERVAL 1 YEAR to '2024-02-29' returns '2025-02-28', not March 1.
  • Implicit DATETIME upgrade: Adding INTERVAL 2 HOUR to a DATE like '2026-05-12' upgrades the return type to '2026-05-12 02:00:00'.

Frequently Asked Questions

What happens if I pass a negative number in INTERVAL?

DATE_ADD('2026-05-12', INTERVAL -3 DAY) subtracts 3 days and returns '2026-05-09', matching DATE_SUB().

Can I write date_col + INTERVAL 7 DAY instead of DATE_ADD()?

Yes. In MySQL, date_col + INTERVAL 7 DAY is a valid shorthand expression with the exact same behavior and clamping rules as DATE_ADD().

Which unit should I use for adding 90 days vs 3 months?

Use INTERVAL 90 DAY for fixed-length trials and INTERVAL 3 MONTH when you want calendar-month billing cycles.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum