SQL INTERVAL
A dedicated type for expressing a SPAN of time — days, months, or years — that adds and subtracts correctly, unlike a plain integer.
What & Why
INTERVAL is its own data type representing a duration — INTERVAL '3 months', INTERVAL '1 year', INTERVAL '2 days'. Unlike plain integer arithmetic (which only ever means days), an interval can express units that don't have a fixed day count, and Postgres handles the calendar math correctly — adding a month to January 31st correctly lands on a real date, not an invalid one.
See How It Works
Growth wants to see day-, hour-, and calendar-month intervals applied to each real signup timestamp.
| id | created_at | country | channel | plan | activated_at | churned_at |
|---|---|---|---|---|---|---|
| 101 | 2024-01-15 09:10:00+00 | US | organic | pro | 2024-01-16 14:25:00+00 | NULL |
| 102 | 2024-02-10 11:05:00+00 | CA | paid | free | NULL | 2024-03-20 10:00:00+00 |
| 103 | 2024-03-12 16:35:00+00 | GB | referral | pro | 2024-03-13 08:15:00+00 | NULL |
| 104 | 2024-04-01 13:20:00+00 | US | organic | free | 2024-04-03 12:00:00+00 | NULL |
| id | created_at | activation_deadline |
|---|---|---|
| 101 | 2024-01-15 09:10:00+00 | 2024-01-22 09:10:00+00 |
| 102 | 2024-02-10 11:05:00+00 | 2024-02-17 11:05:00+00 |
| 103 | 2024-03-12 16:35:00+00 | 2024-03-19 16:35:00+00 |
| 104 | 2024-04-01 13:20:00+00 | 2024-04-08 13:20:00+00 |
The first query result column applies the seven-day interval to every displayed growth.users row.
SELECT
id,
created_at,
created_at + INTERVAL '7 days' AS activation_deadline,
created_at + INTERVAL '2 hours' AS two_hours_later,
created_at + INTERVAL '1 month' AS one_month_later
FROM growth.users
ORDER BY created_at, id;Practice this concept
Growth wants day, hour, and calendar-month intervals applied to every displayed signup timestamp.
growthPrefix tables with growth.table_name.
idcreated_atactivation_deadlinetwo_hours_laterone_month_latergrowth.users| Column | Type |
|---|---|
| id | integer |
| created_at | timestamp with time zone |
| country | text |
| channel | text |
| plan | text |
| activated_at | timestamp with time zone |
| churned_at | timestamp with time zone |
| legacy_user_code | text |
Sign up free to try it on a real business scenario