Learn SQL/Intermediate/Date & Time/SQL Add Months to a Date

SQL Add Months to a Date

Months don't have a fixed day count, so this needs INTERVAL, not plain integer addition.

What & Why

Unlike adding days, adding months can't be done with a plain integer — date_column + 3 always means 3 days, never 3 months. Adding months requires INTERVAL '3 months', letting Postgres handle the calendar math (different month lengths, leap years) correctly.

See How It Works

BUSINESS QUESTION

Marketing wants a one-month review date for every campaign.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT
  name,
  start_date,
  (start_date + INTERVAL '1 month')::date AS review_date
FROM marketing.campaigns
ORDER BY start_date, name;
RESULT — exact output from the displayed Queryflo rows
namestart_datereview_date
Spring Launch2024-01-152024-02-15
Retention Webinar2024-02-102024-03-10
Finance Retargeting2024-03-122024-04-12
Enterprise Search2024-04-012024-05-01

The review date moves each campaign start by one calendar month.

Now You Try

Practice this concept

Marketing wants a one-calendar-month review date for every campaign.

Available schema
marketing

Prefix tables with marketing.table_name.

namestart_datereview_date
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario