Add days or months to a date in SQL
Renewal dates, follow-up deadlines, "the last 30 days": all date arithmetic. In SQLite you pass modifiers to date(): '+7 days', '-1 month', 'start of month'.
Syntax
-- SQLite (this site)
date(d, '+30 days')
-- SQL Server
DATEADD(day, 30, d)
| id | started_at | trial_check_in | first_renewal | month_started |
|---|---|---|---|---|
| 1 | 2026-01-03 | 2026-01-17 | 2026-02-03 | 2026-01-01 |
| 2 | 2026-01-11 | 2026-01-25 | 2026-02-11 | 2026-01-01 |
| 3 | 2026-01-10 | 2026-01-24 | 2026-02-10 | 2026-01-01 |
| 4 | 2026-01-17 | 2026-01-31 | 2026-02-17 | 2026-01-01 |
| 5 | 2026-01-21 | 2026-02-04 | 2026-02-21 | 2026-01-01 |
| 6 | 2026-01-15 | 2026-01-29 | 2026-02-15 | 2026-01-01 |
| 7 | 2026-02-12 | 2026-02-26 | 2026-03-12 | 2026-02-01 |
| 8 | 2026-01-25 | 2026-02-08 | 2026-02-25 | 2026-01-01 |
8 rows
Month-end gotcha: adding a month to Jan 31 has no right answer. SQLite rolls over (Jan 31 + 1 month = Mar 3), while SQL Server and Postgres stop at the last day of February. Check your database before relying on it for billing dates.
"The last 30 days" relative to today: WHERE order_date >= date('now', '-30 days'). (The practice data stops in June 2026, so that returns nothing here.)
In other databases
- SQL Server, Snowflake:
DATEADD(day, 30, d),DATEADD(month, 1, d) - MySQL:
DATE_ADD(d, INTERVAL 30 DAY) - Postgres:
d + INTERVAL '30 days' - BigQuery:
DATE_ADD(d, INTERVAL 30 DAY)
Your turn
Orders placed in the 7 days up to and including 2026-06-30: show id and order_date. (Hint: compare with a date 6 days earlier.)
order_date >= date('2026-06-30', '-6 days') AND order_date <= '2026-06-30'.
This page on one card
