Sheets Tip 204: How To Use Dates In The QUERY Function



Hi Reader,

Welcome to the Google Sheets Tips newsletter #204!

➜ News

I. The QUERY Function Course
​
In case you missed the announcement earlier today, my newest course is now open for enrollment! Find out more:

​The QUERY Function in Google Sheets​

(Enjoy 50% off this week, until Friday at midnight EDT.)

_______

➜ Google Sheets Tip #204: How To Use Dates In The QUERY Function

Here is your Google Sheets tip, which you can think of as your Monday morning espresso, in spreadsheet form.

Working with dates in the QUERY function is tricky.

With today's tip, I want to show you how to reference dates correctly in the QUERY function.

Attempt 1: Try A Regular Date ❌

If you simply drop a date into your QUERY function, for example as a condition in the WHERE filter, it won't return the data you're looking for.

This formula does NOT return any data:

=QUERY( A1:E100 , "select * where B > '5/16/2022' ")

Attempt 2: Try A Formatted Date ❌

The QUERY function needs dates in the ISO format, which is "YYYY-MM-DD".

That's a 4-digit year, a dash, two digits for the month, a dash, and finally, two digits for the day.

For example, today's date is written 2022-05-16.

Putting that into the formula looks like this:

=QUERY( A1:E100 , "select * where B > '2022-05-16' ")

Unfortunately, it still doesn't return any results. Hmm, there's one more thing we need to do...

Attempt 3: Add the "date" Keyword ✅

The last piece of the puzzle is to add the "date" keyword before the date in your filter condition, like this:

=QUERY( A1:E100 , "select * where B > date '2022-05-16' ")

Woohoo!

Now the QUERY function will parse the data correctly and return all data after today's date.

Read more about filtering dates with the QUERY function.

Or, dive deep into the QUERY function (including dates!) in my new course:

​The QUERY Function in Google Sheets​

_______

If you enjoyed this newsletter, please forward it to a friend who might enjoy it.

Have a great week!

Cheers,
Ben

Google Sheets Tips

Get better at working with Google Sheets! Join 50,000 readers to get an actionable tip in your inbox every Monday.

Read more from Google Sheets Tips
Add a QA check to prompts to make them more accurate

Hi Reader, Welcome to the Future Proof newsletter, your Monday morning espresso, in AI form! (Formerly the Google Sheets Tips newsletter.) One of the stories that jumped out to me in the past week came from an interview with a tearful Cornell mathematics professor, asking "what's the point?" when AI surpasses human ability and steals the meaning (and joy) from mathematical research. (Which is a calling, not just a job to many.) One line stuck with me, and I'm paraphrasing here, but basically,...

Add custom Gemini instructions in sidebar of Google Sheets

Hi Reader, Welcome to the Future Proof newsletter issue 5, your Monday morning espresso, in AI form! (Formerly the Google Sheets Tips newsletter.) Lots of Gemini and Google Workspace news to share today and a tip on custom instructions. Find it all below, but first a little anecdote from my weekend. Kids say the funniest things. My 9-year-old declared over the weekend that he was going to build his own AI company and call his AI tool "Psycho"! I laughed and told him I loved the name. I was...

Output Google Doc as markdown file

Hi Reader, Welcome to Future Proof #4 (formerly the Google Sheets Tips newsletter), your Monday morning espresso, in AI form! My son and I had some fun 3-D printing over the weekend. I printed a rugged case to hold my Field Notes journals (see the finished result at the end of this email). The print run just beginning. It's impressive to watch something grow from nothing, although since the full print took around 3 hours I didn't watch the whole thing ;) And now, perhaps more than ever...