Google Sheets Tips

How to filter by date with QUERY in Google Sheets

QUERY compares dates only when the date is written as date 'yyyy-mm-dd'. This guide works every pattern on one request a CEO makes, show me last quarter only: a date from a cell, between two dates, today, a month or a quarter, date-time columns, and the three ways the date filter fails.

Google Sheets TipsVadym Kramarenko18 min read

How to filter by date with QUERY in Google Sheets

To filter by date in a Google Sheets QUERY, write the date as date ‘yyyy-mm-dd’ inside the query string, for example =QUERY(A1:F15, "select * where A >= date '2026-07-01'", 1). The word date, the single quotes and the year-month-day order are all required: a date typed as 07/01/2026, with or without quotes, either returns an error or returns nothing.

You need Query string
Rows after a date (date greater than) "select * where A > date '2026-09-01'"
Rows between two dates "select * where A >= date '2026-07-01' and A < date '2026-10-01'"
A date taken from a cell "select * where A >= date '" & TEXT(I1, "yyyy-mm-dd") & "'"
Rows before today "select * where A < date '" & TEXT(TODAY(), "yyyy-mm-dd") & "'"
The last 30 days "select * where A >= date '" & TEXT(TODAY()-30, "yyyy-mm-dd") & "'"
One month (September 2026) "select * where year(A) = 2026 and month(A) = 8"

The 8 in the last row is not a typo: the query language counts months from 0. That, and the rest of the patterns, are explained below. For the function itself, see the guide to the QUERY function.

This guide works every formula on one request, the one a CEO makes when the quarter has closed and the export has not: show me last quarter only. The answer is one QUERY with two dates in it. Getting there shows why the first version is usually not the answer: on the orders export below, the same “last quarter” returns $6,630, $7,870 or $7,420, and each of the three is arithmetically correct for the rows it let in.

Reading to get this done?

The question and the sheet

The question and the sheet

The sheet is an orders export from the store’s sales platform, pulled on November 27, 2026. Fourteen orders, one per row, header in row 1 and data in rows 2 to 15:

Column Holds
A Order date
B Order ID
C Channel: Paid search, Organic search, Email or Paid social
D Region: US, EU or UK
E Revenue
F Status: Paid or Refunded

Last quarter is Q3 2026, July 1 to September 30. The export does not respect that boundary: it starts with one June order and ends with two October ones. One order, #1050 for $1,240 on September 14, arrived with its date as text (“09/14/2026”) instead of a date, which happens when a file is pasted from another tool or another locale. And one Q3 order, $450 from paid social, was refunded. None of this is unusual. All of it changes the answer.

A Google Sheets orders export with fourteen rows, columns for order date, order ID, channel, region, revenue and status, with the date in A11 already fixed, and a QUERY in H1 that returns Q3 2026 revenue by channel with refunds left out: Paid search $3,220, Organic search $1,950, Email $1,640, Paid social $610, total $7,420.

The finished answer sits on the right of the sheet:

Channel Q3 2026 revenue, refunds excluded Share
Paid search $3,220 43%
Organic search $1,950 26%
Email $1,640 22%
Paid social $610 8%
Total $7,420 100%

Shares are rounded, so they add to 99%. The channel lines are one formula in H1; the share beside each is that line divided by the total, and the total is a SUM of the column:

=QUERY(A1:F15, "select C, sum(E) where A >= date '2026-07-01' and A < date '2026-10-01' and F <> 'Refunded' group by C order by sum(E) desc label sum(E) 'Revenue'", 1)

The rest of this guide builds it from the simplest date filter up.

The working formula: the date keyword and yyyy-mm-dd

The working formula: the date keyword and yyyy-mm-dd

QUERY takes three arguments:

=QUERY(data, query, [headers])

  • data: the range to query.
  • query: the query string, in quotes.
  • headers (optional): the number of header rows at the top of the range.

To return last quarter’s orders, and to explain the formula part by part:

=QUERY(A1:F15, "select * where A >= date '2026-07-01' and A <= date '2026-09-30'", 1)

  • A1:F15: the data, header row included.
  • select *: return all columns.
  • where A >= date ‘2026-07-01’: keep the rows dated on or after July 1, 2026.
  • and A <= date ‘2026-09-30’: and on or before September 30.
  • 1: the range has one header row, and it is carried over to the result.

Google Sheets with the orders export and the formula =QUERY(A1:F15, “select * where A >= date ‘2026-07-01’ and A <= date ‘2026-09-30’”, 1) in H1, returning ten Q3 orders; the text date 09/14/2026 in A11 is highlighted and order #1050 is missing from the result.

The formula returns ten rows, July 3 to September 30, worth $6,630. The dates in the sheet can be displayed in any format, 9/30/2026 or 30 Sep 2026: the format in the query string does not depend on it and is always yyyy-mm-dd.

Count the September rows in the result and there are three. The quarter had four. Order #1050, the $1,240 one with the text date, is not in the result, and nothing on the sheet says so. That is the first of the three totals, and the most dangerous one, because it looks finished. The fix is in “Why the query returns nothing or the wrong rows” below; once the date in A11 is a real date, the same formula returns eleven rows and $7,870.

Hand this to your AI

Some dates arrived as text, so your QUERY date filter returns fewer rows than the tab holds and says nothing.

Paste this into your AI assistant. It writes the date filter for your own QUERY and finds the rows whose dates the sheet can't read.

The prompt

write the QUERY date filter for my sheet's date column, and find the rows where the date is stored as text or in the wrong format

Three ways the date filter fails

Three ways the date filter fails

The three formulas below ask for the same thing as the one above, orders from July 1, and write the date in the three ways people try first. They query the data rows only, A2:F15, with 0 header rows.

Google Sheets with three failing QUERY formulas side by side: a plain date 07/01/2026 returns #VALUE! (Unable to parse query string), a date in quotes ‘07/01/2026’ returns #N/A (Query completed with an empty output), and date ‘07/01/2026’ returns #VALUE! (Invalid date literal).

A plain date returns #VALUE!

=QUERY(A2:F15, "select * where A >= 07/01/2026", 0)

Without the date keyword, QUERY does not read 07/01/2026 as a date, and it reports that it is unable to parse the query string.

A date in quotes returns nothing

=QUERY(A2:F15, "select * where A >= '07/01/2026'", 0)

Anything in single quotes is a text string. A date column never passes a comparison with a piece of text, so no row passes and the result is #N/A with the message “Query completed with an empty output”. With a header row in the result (1 as the last argument) you get the header and no rows, without any error. This one is easy to miss, because the query is valid. A report that says “no orders last quarter” is a different conversation from a report that shows an error.

The date keyword with the wrong format returns #VALUE!

=QUERY(A2:F15, "select * where A >= date '07/01/2026'", 0)

The keyword is there, but the date is not in year-month-day order. The error text says so directly: date literals should be of the form yyyy-MM-dd.

Use a date from a cell

Use a date from a cell

A date typed into the query has to be edited by hand every quarter, by whoever remembers. Keep the two boundary dates in cells instead and build the literal with TEXT, which turns a date into a yyyy-mm-dd string. With the first day of the quarter in I1 and the first day of the next quarter in I2:

=QUERY(A1:F15, "select * where A >= date '" & TEXT(I1, "yyyy-mm-dd") & "' and A < date '" & TEXT(I2, "yyyy-mm-dd") & "'", 1)

  • “select * where A >= date ’”: the first part of the query, up to the opening single quote.
  • TEXT(I1, “yyyy-mm-dd”): the date from cell I1 as text, here 2026-07-01.
  • “’ and A < date ’”: the closing quote of the first date, the second condition and the opening quote of the second date.
  • TEXT(I2, “yyyy-mm-dd”): the date from I2, here 2026-10-01.
  • “’”: the closing single quote.

The parts are joined with ampersands (&). Change the dates in I1 and I2 and the result follows.

To make “last quarter” mean last quarter on any day the sheet is opened, let the two cells work it out from today:

  • I1, first day of last quarter: =EDATE(DATE(YEAR(TODAY()), INT((MONTH(TODAY())-1)/3)*3+1, 1), -3)
  • I2, first day of this quarter: =DATE(YEAR(TODAY()), INT((MONTH(TODAY())-1)/3)*3+1, 1)

On November 27, 2026, I2 returns October 1, 2026 and I1 returns July 1, 2026. On January 5, 2027, I1 moves to October 1, 2026 and I2 to January 1, 2027, without anyone touching the sheet.

Google Sheets with the first day of last quarter in I1 (2026-07-01) and the first day of this quarter in I2 (2026-10-01), both calculated from TODAY, and a QUERY in H4 that builds both date literals with TEXT and returns the eleven Q3 orders, with the date in A11 fixed.

If the cell holds a date typed as text, wrap it in DATEVALUE first: TEXT(DATEVALUE(I1), "yyyy-mm-dd"). With a real date in the cell both versions return the same rows.

Passing the cell without TEXT does not work. "select * where A >= " & I1 puts the serial number of the date into the query, and comparing a date column with a number returns no rows.

Filter between two dates

Filter between two dates

Join two conditions with and. Two ways to write the quarter:

=QUERY(A1:F15, "select * where A >= date '2026-07-01' and A <= date '2026-09-30'", 1)

=QUERY(A1:F15, "select * where A >= date '2026-07-01' and A < date '2026-10-01'", 1)

On this sheet both return the same rows. The second one is the safer habit: “on or after the first day, before the first day of the next period” never depends on how long the month is, and it keeps working when the column carries times as well as dates (see “Date-time columns”). The boundary matters in money: written as A < date '2026-09-30' by mistake, the query drops the September 30 order and returns nine rows and $6,090.

The same pattern answers any range between two dates. August alone, where A >= date '2026-08-01' and A < date '2026-09-01', returns three orders and $2,110. Use > and < instead of >= and <= to leave the two boundary dates out. The from date cannot be greater than the to date: a range written the wrong way round is valid and returns no rows.

To answer the CEO’s real question, revenue by channel for the quarter, add the conditions and a group by:

=QUERY(A1:F15, "select C, sum(E) where A >= date '2026-07-01' and A < date '2026-10-01' and F <> 'Refunded' group by C order by sum(E) desc label sum(E) 'Revenue'", 1)

  • select C, sum(E): one row per channel with its revenue.
  • F <> ‘Refunded’: leave out the refunded order. Text values take single quotes, dates take date and single quotes.
  • group by C: one line per channel.
  • order by sum(E) desc: the biggest channel first.
  • label sum(E) ‘Revenue’: a readable header instead of “sum Revenue”.

The same split with SUMIFS, one formula per channel, is in the guide to SUM, SUMIF and SUMIFS.

Sort by date: order by

Sort by date: order by

order by sorts the result without touching the source. Newest first:

=QUERY(A1:F15, "select * where A >= date '2026-07-01' and A < date '2026-10-01' order by A desc", 1)

The first row of the result is #1052, September 30. Leave out desc, or write asc, for oldest first.

A date stored as text does not sort as a date. QUERY reads it as empty, so the row is not where its date says it should be, or, with a date condition in the query, not there at all. Fix the column before sorting, as described in the troubleshooting section.

Filter by today’s date

Filter by today’s date

TODAY() returns the current date, so a filter built on it moves forward every day without anyone editing the formula. TODAY() cannot be written inside the query string; build the date literal outside it, as with a cell. To return the rows dated after today:

=QUERY(A1:F15, "select * where A > date '" & TEXT(TODAY(), "yyyy-mm-dd") & "'", 1)

On this export the result is the header and no rows: the newest order is from October 9, and the sheet is opened on November 27.

The same pattern covers the usual reporting periods:

  • Up to yesterday: where A < date '" & TEXT(TODAY(), "yyyy-mm-dd") & "'
  • The last 30 days: where A >= date '" & TEXT(TODAY()-30, "yyyy-mm-dd") & "'
  • This month so far: where A >= date '" & TEXT(EOMONTH(TODAY(), -1)+1, "yyyy-mm-dd") & "'
  • Last quarter: the two cells I1 and I2 from “Use a date from a cell”.

The last 30 days return nothing here either, and that is a finding in itself: the export stopped on October 9, so the sheet holds no orders from the last 30 days. An empty result is a question about the export before it is a statement about the business.

More on these two functions in the guides to NOW and TODAY and MONTH and EOMONTH.

Filter by month, year or quarter

Filter by month, year or quarter

The query language has its own date functions, and they save you from writing two boundary dates: year(), month(), quarter(), day() and dayOfWeek().

There is one trap: month() counts from 0, so it returns 0-11, not the 1-12 you expect. January is 0, September is 8 and December is 11. This formula looks like a filter for September and returns October:

=QUERY(A1:F15, "select * where year(A) = 2026 and month(A) = 9", 1)

Google Sheets with the formula =QUERY(A1:F15, “select * where year(A) = 2026 and month(A) = 9”, 1) in H1, returning orders #1053 and #1054, dated October 2 and October 9, 2026, because months are counted from zero.

It returns orders #1053 and #1054, October 2 and October 9, $1,090. For September, write month(A) = 8: three orders and $1,620, and the fourth September order is the text date again.

quarter() counts from 1, so last quarter is:

=QUERY(A1:F15, "select * where year(A) = 2026 and quarter(A) = 3", 1)

It returns the same ten rows and $6,630 as the first formula in this guide. Always pair quarter() and month() with year(): an export that spans 2023 to 2026 otherwise mixes four Q3s into one number.

Date-time columns

Date-time columns

Many exports carry a time with the date: 2026-09-30 18:42. When the column holds a date and a time, a date literal stands for midnight of that day. That has two consequences:

  • where A <= date '2026-09-30' leaves out every order placed on September 30 after midnight, so the last day of the quarter goes missing.
  • where A = date '2026-09-30' returns nothing, because no timestamp is exactly midnight.

Three ways to handle it:

  • Use the first day of the next period: where A >= date '2026-07-01' and A < date '2026-10-01', the form this guide uses throughout.
  • Compare the day only: where toDate(A) = date '2026-09-30'
  • Compare with a moment in time: where A > datetime '2026-09-30 13:00:00'

Filter by date without QUERY: the FILTER function

Filter by date without QUERY: the FILTER function

If all you need is the rows, the FILTER function filters by date with no query string and no date literal:

=FILTER(A2:F15, A2:A15 >= DATE(2026,7,1), A2:A15 < DATE(2026,10,1))

It returns the same Q3 rows as the QUERY, without a header, and it skips the text date too. Each condition range must be as tall as the data: A2:A15 with A2:F15 works, D2:D12 with A2:F15 returns #VALUE! for mismatched range sizes. Use QUERY when you also want to group, sort or pick columns in the same formula.

To filter by date in place, without a formula, use Data > Create a filter, then on the Order date column choose Filter by condition > Custom formula is and enter =AND(A2>=DATE(2026,7,1), A2<DATE(2026,10,1)) for a date range.

Why the query returns nothing or the wrong rows

Why the query returns nothing or the wrong rows

⚠️ Error: #VALUE! with “Unable to parse query string”.

✅ Solution: The date is written without the date keyword or in the wrong order. Write it as date ‘yyyy-mm-dd’. When the literal is built from a cell, check that the single quotes are there on both sides of the TEXT part.

⚠️ Error: #N/A with “Query completed with an empty output”, or a header with no rows.

✅ Solution: The date is compared with a quoted string or with a number. Add the date keyword and build the value with TEXT(cell, “yyyy-mm-dd”). If the formula is right, check the export: a filter on the last 30 days of a file that ends two months ago is empty for a good reason.

⚠️ Error: Some rows are missing, although their dates match.

✅ Solution: Those dates are stored as text. QUERY assigns one type to each column, the type of most of its cells, and treats the other cells as empty. A text date is usually left-aligned and does not change when you change the number format. Here it is A11, and it costs the quarter $1,240. Retype the cell as a date, or, for an export that keeps arriving this way, add a helper column, =ARRAYFORMULA(IF(ISTEXT(A2:A15), DATEVALUE(A2:A15), A2:A15)) in G2, format column G as a date and point the query at G. DATEVALUE reads the text in the spreadsheet’s locale, so 09/14/2026 converts under a US locale. The guides to DATE functions and ARRAYFORMULA cover both functions.

⚠️ Error: The wrong month comes back.

✅ Solution: month() counts from 0. Subtract 1 from the month number.

⚠️ Error: The last day of the period is missing.

✅ Solution: The column holds date-times and the query ends with <= date of the last day. End it with < date of the first day of the next period.

⚠️ Error: Curly quotes in a copied formula.

✅ Solution: A formula pasted from a document or a chat can carry typographic quotes (‘ ’ or “ ”) instead of straight ones. Retype the quotes in the formula bar.

⚠️ Error: The total is right, and it does not match the other report.

✅ Solution: Both can be right. On this sheet, “last quarter” is $6,630, $7,870 or $7,420, and the export as a whole is $9,600:

Google Sheets with four totals of the same orders export: every row $9,600, Q3 as first written $6,630, Q3 with the text date fixed $7,870, and Q3 orders that were kept $7,420.

What the formula lets in Total
Every row in the export $9,600
Q3, as first written: the text date is skipped, the refund is in $6,630
Q3 with the text date fixed, refund still in $7,870
Q3 orders that were kept, refund out $7,420

The gaps have names: $1,730 of orders outside the quarter, $1,240 on a date nobody could read, $450 refunded. Before comparing two reports, check the same five things:

  • Period: which dates are in, whether the last day counts, and which time zone the export uses.
  • Unreadable dates: text dates, blank dates, a column of a different type.
  • Refunds and cancellations: in or out.
  • Gross or net: before or after discounts and tax.
  • Attribution: the channel recorded on the order, or the channel an ad platform claims.

Write the conditions next to the number. Two numbers that differ for a reason you can name are a finding; two that differ for no reason anyone can name are a trust problem, and the next number from the same sheet will be doubted too.

Related Google Sheets functions

Functions that are often used next to a date filter in QUERY, each with its own guide:

  • FILTER: Returns the rows that meet a condition; for a simple date filter it needs no query string.
  • QUERY with CONCATENATE: Builds query strings from parts, the same technique as the date from a cell.
  • DATE: A set of functions for managing dates, including DATE for creating valid dates, EDATE for adjusting by months, DATEVALUE for converting text to dates and DATEDIF for calculating date differences.
  • YEAR/YEARFRAC: Extracts the year from a date or returns the fraction of a year between two dates.
  • MONTH/EOMONTH: Extracts the month from a date or returns the last day of a month, handy for monthly reports.
  • WEEKDAY/WEEKNUM: Returns the day of the week or the week number of the year for a date, useful for weekly reporting.
  • UNIQUE: Returns the distinct values of a range.
  • Pivot tables: Summarize the filtered rows by month, channel or region; a pivot table can also filter by condition on a date column.

The date filter is only as good as the dates in the tab

The date filter is only as good as the dates in the tab

Every pattern above assumes that column A holds real dates. In a report that is fed by exports this is the part that breaks: one file writes 09/14/2026, the next one 2026-09-14 as text, a third one adds a time. QUERY does not complain. It treats the cells it cannot read as empty, and the report quietly shows fewer rows than there are. On this sheet that was $1,240, the biggest order of the quarter, and it was enough to make paid search and organic search look level ($1,980 against $1,950) when paid search brought in $3,220. The formula was exact. The rows were not.

The OWOX Data Marts extension for Google Sheets covers that half. A data analyst publishes a Data Mart (a table or an SQL query in your data warehouse, with the definitions the team agreed, such as what counts as a refund and which time zone a day is in) and makes it available for reports. In Sheets you open the extension, pick the Data Mart, tick the columns you want and run it. The rows land in a tab, with the date column typed as a date, ready for your QUERY.

Google Sheets with the OWOX Data Marts extension open beside an ad spend table: the Unified Ad Spend Data Mart, nine of fourteen columns ticked and a Save & Run button – the rows in the sheet come from a governed Data Mart, not a pasted export

What changes for the person who owns the number:

  • Refresh replaces re-export. Refresh current report in the extension menu re-runs the same pull, and a scheduled refresh keeps the tab current without anyone touching it.
  • The source is written on the sheet. The header cell of an imported tab carries a note with the Data Mart it came from, the time of the import and a link to the report.
  • No SQL and no data warehouse access needed. The analyst decides which Data Marts and columns are available. You choose from that list.

The extension does not write or change the analyst’s SQL, and it does not replace QUERY: you still decide which period to show and which rows count. What the sheet receives is the result of the same query on every refresh, not a new export with a new date format, so a QUERY date filter written once keeps reading the same column. The extension comes with the OWOX Cloud plans of OWOX Data Marts; spreadsheet reporting describes both ways data reaches a sheet.

Hand this to your AI

Some dates arrived as text, so your QUERY date filter returns fewer rows than the tab holds and says nothing.

Paste this into your AI assistant. It writes the date filter for your own QUERY and finds the rows whose dates the sheet can't read.

The prompt

write the QUERY date filter for my sheet's date column, and find the rows where the date is stored as text or in the wrong format

FAQ

Frequently Asked Questions

How do I filter data between two specific dates using the QUERY function?

Join two conditions with `and`, and write each date with the `date` keyword in yyyy-mm-dd format. For last quarter on an orders export with the date in column A: `=QUERY(A1:F15, "select * where A >= date '2026-07-01' and A < date '2026-10-01'", 1)`. Ending on the first day of the next period, with `<`, keeps the last day of the quarter even when the column carries times. On a 14-order export the formula returns the ten Q3 orders, $6,630, and leaves out the June and October orders on either side.

What common issues arise with date handling in the QUERY function?

A date typed without the `date` keyword returns #VALUE!, and a date in quotes without the keyword returns no rows. The quiet one is a date stored as text: QUERY treats it as empty, so the row drops out with no error. On a 14-order export, one text date cost last quarter $1,240, its biggest order. Also: `month()` counts from 0, so September is 8, and in a date-time column a date literal means midnight, so `<= date` of the last day loses that day's orders.

Can I use today’s date as a filter in my QUERY?

Yes. TODAY() cannot be written inside the query string, so build the date literal outside it: `"select * where A >= date '" & TEXT(TODAY()-30, "yyyy-mm-dd") & "'"` returns the last 30 days. For last quarter, keep its first day and the first day of this quarter in two cells calculated from TODAY() and point the query at them. The filter then moves forward on its own. If it returns nothing, check the export first: a file that ends on October 9 holds no orders from the last 30 days on November 27.

How can I ensure my dates are recognized by the QUERY function?

Write the date in the query as date 'yyyy-mm-dd': the word date, single quotes and year-month-day order. The column itself must hold real dates, not text. A text date, such as 09/14/2026 pasted from another tool, is usually left-aligned and does not change when you change the number format. Retype it, or convert the column with `=ARRAYFORMULA(IF(ISTEXT(A2:A15), DATEVALUE(A2:A15), A2:A15))` formatted as a date. Otherwise QUERY skips those rows and the total comes out lower with no error.

Why is it crucial to use date filtering in the QUERY function?

Because an export rarely matches the period you report on. An orders export pulled in late November starts with a June order and ends with October ones, so its total, $9,600 on a 14-order example, is not last quarter. A date filter keeps only July 1 to September 30. Then write down what else the number includes: with a text date fixed and one refund left out, the same quarter is $7,420, not the $6,630 the first filter returned.

What is the QUERY function in Google Sheets?

QUERY runs a query string in a SQL-like language over a range: `=QUERY(data, query, [headers])`. One formula can filter, sort, group and sum. On an orders export, `=QUERY(A1:F15, "select C, sum(E) where A >= date '2026-07-01' and A < date '2026-10-01' and F <> 'Refunded' group by C", 1)` returns last quarter's revenue by channel, refunds left out. It reads what is in the range, so a date stored as text or a pasted export with missing rows changes the result without an error.

Who wrote this

Vadym Kramarenko

Vadym Kramarenko Growth Marketing Manager

Vadym Kramarenko is a Growth Marketing Manager at OWOX, where he drives user acquisition and product-led growth strategies. He hosts the OWOX podcast, interviewing analytics professionals about data-driven marketing, attribution, and reporting best practices. Vadym specializes in turning complex analytics concepts into practical, actionable marketing frameworks.