Quarter to Date in SQL
Quarter to date totals everything from the first day of the current quarter up to today, and can be compared with the same stretch last year.
Example query
This example assumes: orders(id, order_date date, total_amount numeric). It is written in PostgreSQL syntax, and your table and column names will differ from these.
SELECT SUM(total_amount) AS quarter_to_date_sales
FROM orders
WHERE order_date >= DATE_TRUNC('quarter', CURRENT_DATE)
AND order_date < CURRENT_DATE + 1;The same stretch of last year's quarter
SELECT SUM(total_amount) AS same_period_last_year
FROM orders
WHERE order_date >= DATE_TRUNC('quarter', CURRENT_DATE) - INTERVAL '1 year'
AND order_date < CURRENT_DATE + 1 - INTERVAL '1 year';How it works
- DATE_TRUNC('quarter', CURRENT_DATE) is the first day of the current quarter.
- The upper bound is tomorrow, so today's orders are included.
- The alternative shifts both bounds back a year to give a like-for-like comparison of the same days.
MySQL, BigQuery, SQL Server and SQLite differences
- The same idea works anywhere; only the truncation function changes. In MySQL use MAKEDATE and QUARTER or a calendar table; in BigQuery use DATE_TRUNC(CURRENT_DATE(), QUARTER).
Common mistakes
- Fiscal quarters rarely match calendar quarters; use a fiscal calendar table if yours differ.
- Comparing quarter to date with a full prior quarter understates growth.
- Leap years shift the same-period comparison by a day.
Ask for it in plain English
Instead of writing the query yourself, you can type the question. SchemaChat turns it into SQL against your connected database or uploaded file, runs it, and shows the SQL and the figures it used so you can check the answer before you share it. Check that the query matches the definition your business uses.
- What are our sales quarter to date compared with the same point last year?
- How much have we invoiced so far this quarter?