The Google Sheets Query Function by Coding is for Losers
Login Buy for $49

Date Comparisons in Queries: Why so Complex?

The Google Sheets Query Function / Getting Started with Sheets Queries
When I first started writing date comparisons within Google queries (pulling data before / after a certain date), it was a pain to figure out the correct syntax.  

=query(D:G, “select E where D greater than date ‘2016-08-22’”)

Unfortunately it’s not really mentioned anywhere in the Google Sheets documentation, so I had to figure it out for myself.  

You have to do two things correctly:

- Write the string ‘date’ before the actual date, to declare your intentions
- Type your date in the format ‘yyyy-mm-dd’

If you want to compare a date dynamically from another cell, it’s a bit of a different story.  I like to keep date ranges (last 7 days, last 30 days, year-to-date, etc), then reference them in a query like this:

=query(D:G, “select E where D greater than date ‘“ & text(B1, “yyyy-mm-dd”) & “‘“)

Notice the syntax:

- To combine the string with an outside value, close the query double-quotes, and use ‘&’ 
- Use the TEXT function to convert the date into the correct ‘yyyy-mm-dd’ format

The Google Sheets Query Function

A weapon of mass laziness

Buy for $49 Learn more
Already enrolled?
Sign in to continue learning.

Table of contents

The Google Sheets Query Function

by Coding is for Losers
ui-24px-outline-1_lock
Getting Started with Sheets Queries Getting Started with Sheets Queries
Draft Browse the Sample Dataset
Draft Browse the Sample Dataset
Draft Writing your first Sheets Query
Draft Writing your first Sheets Query
Draft Date Comparisons in Queries: Why so Complex?
Draft Date Comparisons in Queries: Why so Complex?
Draft Query multiple Google Sheets: IMPORTRANGE + {} = FRIENDS
Draft Query multiple Google Sheets: IMPORTRANGE + {} = FRIENDS
ui-24px-outline-1_lock
Writing Basic Queries Writing Basic Queries
Draft Intro: Doing Math in Queries
Draft Intro: Doing Math in Queries
Draft Question 1: Pulling the Top Questions
Draft Question 1: Pulling the Top Questions
Draft Question 2: Who are the Top Tweeters?
Draft Question 2: Who are the Top Tweeters?
Draft Question 3: What's the Most Active Day of the Week?
Draft Question 3: What's the Most Active Day of the Week?
Draft Quiz 1: Basic Querying
Draft Quiz 1: Basic Querying
ui-24px-outline-1_lock
Writing Advanced Queries Writing Advanced Queries
Draft Intro: Diving Deeper
Draft Intro: Diving Deeper
Draft Question 4: What's the Top Hour of the Day?
Draft Question 4: What's the Top Hour of the Day?
Draft Question 5: What are the Most-Used Hashtags?
Draft Question 5: What are the Most-Used Hashtags?
Draft Question 6: Whata Domains are Most-Tweeted?
Draft Question 6: Whata Domains are Most-Tweeted?
Draft Quiz 2: Advanced Querying
Draft Quiz 2: Advanced Querying
ui-24px-outline-1_lock
Bonus Section: Learn SQL too Bonus Section: Learn SQL too
Draft Transitioning from Query Functions to SQL
Draft Transitioning from Query Functions to SQL
Draft Learn SQL in a Spreadsheet
Draft Learn SQL in a Spreadsheet
Powered by
Terms Privacy
Welcome!
Enter your info below to login.
Forgot your password?