You can filter, sort, and group data by date inside a Google Sheets QUERY formula by writing date criteria in the query string, usually with date, datetime, or comparison operators against a date literal or a cell reference. The trick is formatting the date correctly and understanding that QUERY treats dates as serial numbers. This guide walks through the working syntax, the common pitfalls, and how to handle dates that come in as text.

What You'll Need

  • A Google Sheet with a table that includes a date column (or a column you want to treat as dates).
  • Basic familiarity with the QUERY function syntax: =QUERY(data, query, [headers]).
  • Dates stored as real date values, not plain text. If your dates are text, you will need to convert them first (covered below).
  • Access to Google Sheets on desktop or mobile. The QUERY function works the same in both, though the formula editor is easier on desktop.

Step-by-Step

  1. Check that your date column is a real date. Select the column and look at the format. If dates are left-aligned, they are likely text. Real dates are right-aligned by default. To convert text dates, use DATEVALUE in a helper column or reformat via Format > Number > Date. QUERY will not compare text dates correctly.
  2. Write a basic QUERY that selects all columns. For example, if your data is in A1:C100 and row 1 has headers, enter =QUERY(A1:C100, "SELECT *", 1). This confirms the range and header count are correct before adding date logic.
  3. Add a date filter using a literal. To return rows where the date column (say column B) is after January 1, 2024, use: =QUERY(A1:C100, "SELECT * WHERE B > date '2024-01-01'", 1). The date literal must be in yyyy-mm-dd format inside single quotes, preceded by the keyword date.
  4. Use a cell reference for a dynamic date. If you put a start date in cell E1, the query becomes: =QUERY(A1:C100, "SELECT * WHERE B > date '"&TEXT(E1,"yyyy-mm-dd")&"'", 1). The TEXT function ensures the date is formatted correctly for the query string. Without it, the serial number may be used and the comparison will fail.
  5. Filter between two dates. Combine two conditions with AND: =QUERY(A1:C100, "SELECT * WHERE B >= date '2024-01-01' AND B <= date '2024-12-31'", 1). This is the standard way to get a date range.
  6. Use datetime when your column includes times. If the column has date and time together, use datetime '2024-01-01 00:00:00' in the same format. Mixing date and datetime literals can cause type errors.
  7. Group and aggregate by date. To sum values per day, use: =QUERY(A1:C100, "SELECT B, SUM(C) WHERE B IS NOT NULL GROUP BY B", 1). This treats each distinct date as a group. For month-level grouping, you need a helper column with =EOMONTH(B2,-1)+1 or =TEXT(B2,"yyyy-mm") and then group on that column, because QUERY does not have a built-in month function.
  8. Sort by date. Add ORDER BY B DESC to the end of the query string to show newest first. For example: =QUERY(A1:C100, "SELECT * WHERE B > date '2024-01-01' ORDER BY B DESC", 1).
  9. Handle blank or invalid dates. Use WHERE B IS NOT NULL to skip empty cells. If some cells contain text that looks like a date but is not a real date, those rows will be excluded or cause errors. Clean them first.
  10. Test and adjust. If you get a #VALUE! error, check that the date literal is correctly quoted and that the column letter matches your range. If you get #N/A, the query returned no rows—verify the date range and that the column contains real dates.

Common Mistakes

  • Using a date without the date keyword. Writing WHERE B > '2024-01-01' compares text, not dates, and will give wrong results. Always use date '2024-01-01'.
  • Forgetting the TEXT wrapper for cell references. Concatenating a date cell directly can insert a serial number (e.g., 45292) instead of a formatted date, causing a type mismatch.
  • Assuming QUERY can extract month or year. QUERY does not support functions like MONTH() or YEAR() inside the query string. Create helper columns with those values and query those instead.
  • Mixing date and datetime literals. If your column has times, use datetime; if it has only dates, use date. Using the wrong one can return no results.
  • Ignoring header count. The third argument of QUERY is the number of header rows. If your range includes a header but you pass 0, the header row may be treated as data and cause errors.

Tips

  • Use named ranges to make queries easier to read and maintain.
  • When building dynamic queries with cell references, wrap the entire query string in TEXT for dates to avoid locale issues.
  • For month or year grouping, add a helper column with =TEXT(B2,"yyyy-mm") and group by that column.
  • Test your query with a small range first, then expand.
  • Remember that QUERY is case-sensitive for column letters but not for keywords.

Troubleshooting

If your QUERY returns #VALUE!, the most common cause is a malformed date literal. Check that the date is in yyyy-mm-dd format and enclosed in single quotes after the date keyword. If you used a cell reference, ensure the TEXT function is applied with the correct format string. If you get #N/A, the query likely returned no rows—double-check the date range and that the column contains real dates, not text. If dates appear as numbers, format the column as a date via Format > Number > Date. If you see #ERROR!, review the query syntax for missing commas or mismatched quotes. For persistent issues, simplify the query to SELECT * and add conditions one at a time to isolate the problem.

Frequently Asked Questions

Can I use TODAY() inside a QUERY?

Not directly. QUERY does not evaluate spreadsheet functions inside the query string. Instead, put =TODAY() in a cell and reference that cell using the TEXT concatenation method.

Why does my date filter return no results even though dates exist?

Most likely the dates are stored as text. Check alignment: text is left-aligned, real dates are right-aligned. Convert them with DATEVALUE or by reformatting the column.

How do I filter for a specific month?

QUERY has no month function. Add a helper column with =TEXT(B2,"yyyy-mm") and then use WHERE D = '2024-01' (assuming the helper is in column D).

Can I use BETWEEN for dates?

QUERY does not support BETWEEN. Use two conditions with AND: WHERE B >= date '2024-01-01' AND B <= date '2024-12-31'.

Does QUERY work with dates in mobile Google Sheets?

Yes, the QUERY function works the same on mobile, but the formula bar is smaller. You can still type the full query string.

What if my date column includes times?

Use datetime literals instead of date, for example datetime '2024-01-01 00:00:00'. Mixing types will cause errors.