How to Filter Google Sheets QUERY Function by Date Range (With Examples)

The QUERY function is arguably the most versatile tool in Google Sheets. It allows you to run SQL-like database queries directly on your spreadsheet data to filter, sort, and aggregate information. However, filtering data by dates inside a QUERY formula is a common point of confusion.

If you try to compare dates using standard text formats, Google Sheets will often return a #VALUE! error or blank results. In this guide, you will learn the exact date formatting syntax needed to filter Google Sheets QUERY results by single dates, date ranges, and dynamic cell references.


Why QUERY Date Filtering Fails (And How to Fix It)

Inside a standard Google Sheets cell, dates are displayed in human-readable formats like 2026-08-10 or 10/08/2026. However, the QUERY engine treats unformatted dates as plain text or raw serial numbers.

To filter by date successfully, you must explicitly declare the data type as date and format your date string as 'YYYY-MM-DD' inside your SQL clause:

date 'YYYY-MM-DD'

1. Filter Data After a Specific Date

To return all rows where the date in Column A is on or after January 1, 2026, use the >= operator with the formatted date literal:

=QUERY(A1:D100, "SELECT * WHERE A >= date '2026-01-01'", 1)

2. Filter Data Between Two Dates (Date Range)

To extract records falling within a specific date range (for example, Q1 financial transactions between January 1, 2026, and March 31, 2026), combine two conditions using the AND keyword:

=QUERY(A1:D100, "SELECT * WHERE A >= date '2026-01-01' AND A <= date '2026-03-31'", 1)

3. Filter Using Cell References (Dynamic Dates)

Hardcoding date strings inside your formula isn't practical if you build dynamic dashboards. If your Start Date sits in cell F1 and your End Date sits in cell F2, use the TEXT() function to pass formatted dates dynamically into your QUERY:

=QUERY(A1:D100, "SELECT * WHERE A >= date '"&TEXT(F1, "yyyy-mm-dd")&"' AND A <= date '"&TEXT(F2, "yyyy-mm-dd")&"'", 1)

How This Works:

  • TEXT(F1, "yyyy-mm-dd") converts the date value in cell F1 into the required SQL date format string.
  • The ampersands (&) stitch the dynamic text string into the QUERY statement seamlessly.

Cheat Sheet: Date Operators in Google Sheets QUERY

Objective WHERE Clause Syntax Example
Exact Date Match WHERE A = date '2026-08-10'
Before a Specific Date WHERE A < date '2026-06-01'
Current Month / Today WHERE A = date '"&TEXT(TODAY(), "yyyy-mm-dd")&"'
Exclude Blank Dates WHERE A IS NOT NULL

Best Practices & Troubleshooting Tips

  • Always Use Leading Zeros: Months and days must feature two digits (e.g., 05 for May, not 5).
  • Check Column Types: Ensure your source column contains true Google Sheets dates, not plain text strings. You can verify this by checking if dates align to the right side of cells by default.
  • Combine with SELECT Statements: You can select specific columns while filtering by date: "SELECT A, B, D WHERE C >= date '2026-01-01'".

Comments