SQL Add Days to a Date
The simplest date arithmetic — a plain + sign between a date and a number.
What & Why
date_column + n adds n days to a date. This is the pattern the Date Arithmetic lesson introduced, applied to a concrete, common use case: computing a follow-up date, a deadline, or an expiration.
See How It Works
BUSINESS QUESTION
Marketing wants a seven-day follow-up date for every lead.
| id | campaign_id | created_at | qualified_at | converted_at | lead_score | source | country | |
|---|---|---|---|---|---|---|---|---|
| 301 | 1 | ana@example.com | 2024-01-21 09:10:00+00 | 2024-01-22 11:00:00+00 | 2024-02-02 10:00:00+00 | 86 | google_ads | US |
| 302 | 1 | ben@example.com | 2024-01-24 12:40:00+00 | NULL | NULL | 52 | google_ads | CA |
| 303 | 2 | chloe@example.com | 2024-02-16 08:30:00+00 | 2024-02-18 14:20:00+00 | NULL | 74 | GB | |
| 304 | 3 | dev@example.com | 2024-03-20 17:15:00+00 | 2024-03-21 09:00:00+00 | 2024-04-04 16:00:00+00 | 91 | US |
EXAMPLE QUERY
SELECT
id AS lead_id,
created_at,
created_at + INTERVAL '7 days' AS follow_up_at
FROM marketing.leads
ORDER BY lead_id;RESULT — exact output from the displayed Queryflo rows
| lead_id | created_at | follow_up_at |
|---|---|---|
| 301 | 2024-01-21 09:10:00+00 | 2024-01-28 09:10:00+00 |
| 302 | 2024-01-24 12:40:00+00 | 2024-01-31 12:40:00+00 |
| 303 | 2024-02-16 08:30:00+00 | 2024-02-23 08:30:00+00 |
| 304 | 2024-03-20 17:15:00+00 | 2024-03-27 17:15:00+00 |
Each follow-up timestamp is exactly seven days after lead creation.
Now You Try
Practice this concept
Marketing wants a seven-day follow-up date for every lead.
Available schema
marketingPrefix tables with marketing.table_name.
lead_idcreated_atfollow_up_atmarketing.leads| Column | Type |
|---|---|
| id | integer |
| campaign_id | integer |
| text | |
| created_at | timestamp with time zone |
| qualified_at | timestamp with time zone |
| converted_at | timestamp with time zone |
| lead_score | integer |
| source | text |
| country | text |
| archive_status | text |
query.sql
Sign up free to try it on a real business scenario