SQL Extract Year

Pulls just the year out of a date — the most common single field to extract.

What & Why

EXTRACT(YEAR FROM date_column) returns the calendar year as a plain integer — useful for grouping records by year, or filtering to a specific one.

See How It Works

BUSINESS QUESTION

Marketing wants campaign counts by start year.

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
  EXTRACT(YEAR FROM start_date)::int AS start_year,
  COUNT(*) AS campaign_count
FROM marketing.campaigns
GROUP BY start_year
ORDER BY start_year;
RESULT — exact output from the displayed Queryflo rows
start_yearcampaign_count
20244

All four displayed campaigns start in 2024.

Intermediate business practice

Sign up free to try it on a real business scenario