SQL reference

Add days or months to a date in SQL

In Excel, you'd reach for
fx=A2+30, =EDATE(A2, 1), =WORKDAY()

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)
Try itEdit the query, then Run
idstarted_attrial_check_infirst_renewalmonth_started
12026-01-032026-01-172026-02-032026-01-01
22026-01-112026-01-252026-02-112026-01-01
32026-01-102026-01-242026-02-102026-01-01
42026-01-172026-01-312026-02-172026-01-01
52026-01-212026-02-042026-02-212026-01-01
62026-01-152026-01-292026-02-152026-01-01
72026-02-122026-02-262026-03-122026-02-01
82026-01-252026-02-082026-02-252026-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.)

This page on one card

Add days or months to a date in SQL: the Excel way (=A2+30) and the SQL query, side by side
Add days or months to a date in SQL, on one card: the Excel way and the SQL. Download · Save to Pinterest
The practice data (7 tables)

See every column and sample rows