QUARTER

Extract the calendar quarter (1 through 4) from a date or timestamp.

Category: datetimeReturns: INTEGERDialect: Standard

Syntax

QUARTER(date)

Description

## Overview Extracts the calendar quarter from a DATE or TIMESTAMP, returned as an INTEGER between 1 and 4. Q1 covers January through March, Q2 covers April through June, Q3 covers July through September, Q4 covers October through December. Equivalent to EXTRACT(QUARTER FROM input). Use QUARTER for quarterly reporting and seasonality analysis. For fiscal-quarter reporting that does not align with the calendar year, build a custom mapping using MONTH and a fiscal-year-start offset. ## Behavior - Returns an INTEGER in the range 1 through 4. - Returns NULL if the argument is NULL. - Accepts DATE, TIMESTAMP, and TIMESTAMP WITH TIME ZONE inputs. - Quarter numbering is 1-based (Q1 = January through March). - Quarter boundaries are fixed to calendar months and do not shift for any locale or accounting convention. ## Timezone handling - TIMESTAMP WITH TIME ZONE values are converted to the session zone before the quarter is taken. ## Compatibility - Equivalent to EXTRACT(QUARTER FROM source). Quarter extraction is not part of core SQL but is a de facto standard in analytical SQL engines.

Parameters

NameTypeDescription
dateSpecifies the date or timestamp from which to extract the quarter.

Examples

-- July falls in Q3
SELECT QUARTER(DATE '2025-07-04') AS q;
-- January (Q1 boundary)
SELECT QUARTER(DATE '2025-01-15') AS q;
-- December (Q4 boundary)
SELECT QUARTER(DATE '2025-12-31') AS q;
-- Revenue by quarter across all years
SELECT QUARTER(order_date) AS q, SUM(total_amount) AS revenue
FROM commerce.sales.orders
GROUP BY q
ORDER BY q;
-- Year + quarter cohorts
SELECT YEAR(order_date) AS yr, QUARTER(order_date) AS q, COUNT(*) AS orders
FROM commerce.sales.orders
GROUP BY yr, q
ORDER BY yr, q;
-- Filter to current quarter
SELECT event_id
FROM analytics.events.user_activity
WHERE YEAR(event_ts) = YEAR(CURRENT_DATE())
  AND QUARTER(event_ts) = QUARTER(CURRENT_DATE());

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →