FormulaCraft

How to use QUERY with date comparisons in Excel and Google Sheets

Topic:QUERY (Google Sheets SQL)

Heads up: Excel and Google Sheets do this differently.

Excel
=FILTER(A2:C10,(A2:A10>=DATE(2024,1,10))*(A2:A10<=DATE(2024,1,25)))
Google Sheets
=QUERY(A1:C10,"SELECT A, B, C WHERE A >= date '2024-01-10' AND A <= date '2024-01-25'",1)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Ensure your date column (A) contains real date values, not text strings that look like dates — click a cell and check the formula bar format.
  2. 2To filter for dates on or after a specific date, use: =QUERY(A1:C10,"SELECT A, B, C WHERE A >= date '2024-01-10'",1).
  3. 3To filter a date range, chain two conditions with AND: "SELECT A, B, C WHERE A >= date '2024-01-10' AND A <= date '2024-01-25'".
  4. 4To reference a cell for the date value instead of hardcoding it, use TEXT concatenation: "SELECT A, B, C WHERE A >= date '"&TEXT(E2,"yyyy-mm-dd")&"'".
  5. 5Use QUERY's toDate() or the date functions year(), month(), day() to extract date parts: "SELECT year(A), month(A), SUM(C) GROUP BY year(A), month(A)" rolls data up by year-month.

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Why does my QUERY date filter return all rows or no rows?

The most likely cause is that your date column contains text values rather than true date serial numbers. Select a cell in the column, look at the format, and run =ISNUMBER(A2) — if it returns FALSE the value is text, not a real date.

Can I filter by a specific day of the week?

Yes, using QUERY's dayOfWeek() function: WHERE dayOfWeek(A) = 2 filters for Mondays (1=Sunday through 7=Saturday in the Google Visualization API).

How do I filter dates in the last 30 days dynamically?

Use TODAY() with TEXT: "WHERE A >= date '"&TEXT(TODAY()-30,"yyyy-mm-dd")&"'". This always evaluates to the current date minus 30 days when the sheet recalculates.

More on QUERY (Google Sheets SQL)

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: