SQLPathLab
Date and Time · Basic

DATE_ADD

adding intervals to dates.

Overview

DATE_ADD(date, INTERVAL value unit) adds an interval in the requested unit. Day arithmetic and month arithmetic follow different calendar rules, while month ends, leap years, and DATETIME versus TIMESTAMP time-zone behavior require separate checks. For filtering, calculate boundary constants rather than wrapping every row's column when possible.

Basic syntax

SELECT DATE_ADD(created_at, INTERVAL 7 DAY) FROM orders;

Examples

DATE_ADD example

The example adds seven days to each order timestamp for a due-date calculation; real use must also define the time type and time zone.

Sample table

Table:orders
orders
created_at
2026-01-03
2026-01-08
2026-02-02
2026-02-15

Run result

result
date(created_at, '+7 day')
2026-01-10
2026-01-15
2026-02-09
2026-02-22

Common issues

What happens when one month is added to a month-end date?

Months have different lengths, so the database adjusts according to its rules. Test settlement logic with dates on the 28th through 31st.

Do DATE, DATETIME, and TIMESTAMP behave identically?

Not completely. TIMESTAMP may be affected by the session time zone, so cross-zone systems need explicit storage and display rules.

Should DATE_ADD wrap a column in a date-range filter?

On large tables, calculate the boundary first and compare the column directly to preserve the opportunity for index use.

Tags

CommonDate & time

Was this explanation clear?