SQL Extract Day

Returns the day-of-month number — 1 through 31, depending on the month.

What & Why

EXTRACT(DAY FROM date_column) returns just the day-of-month portion — useful for questions like "which campaigns joined in the first half of the month."

See How It Works

BUSINESS QUESTION

Marketing wants lead volume by day of month.

idcampaign_idemailcreated_atqualified_atconverted_atlead_scoresourcecountry
3011ana@example.com2024-01-21 09:10:00+002024-01-22 11:00:00+002024-02-02 10:00:00+0086google_adsUS
3021ben@example.com2024-01-24 12:40:00+00NULLNULL52google_adsCA
3032chloe@example.com2024-02-16 08:30:00+002024-02-18 14:20:00+00NULL74emailGB
3043dev@example.com2024-03-20 17:15:00+002024-03-21 09:00:00+002024-04-04 16:00:00+0091linkedinUS
EXAMPLE QUERY
SELECT
  EXTRACT(DAY FROM created_at)::int AS month_day,
  COUNT(*) AS leads
FROM marketing.leads
GROUP BY month_day
ORDER BY month_day;
RESULT — exact output from the displayed Queryflo rows
month_dayleads
161
201
211
241

EXTRACT returns each lead timestamp's day of month.

Intermediate business practice

Sign up free to try it on a real business scenario