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

Hi Reader, Welcome to the Google Sheets Tips newsletter #382, your Monday morning espresso, in spreadsheet form! If you feel like the AI wave is moving faster than you can keep up with, you aren't alone. The gap between "playing with a chatbot" and "building reliable AI systems" feels wider than ever, and that feeling is only increasing with every new AI announcement. For the past couple of months, I’ve been working on a new course to help address this challenge. Next Monday, I’m opening...

Hi Reader, Welcome to the Google Sheets Tips newsletter #381, your Monday morning espresso, in spreadsheet form! Since last week, the weather in the Mid-Atlantic region has been even more volatile than that mission critical spreadsheet your non-technical boss "fixed" recently. We had a day over 80F, followed by a wild 50F drop to temps in the 30's and snow squalls. And later today, we're forecast to have a severe thunderstorm and possible tornadoes. It's threatening enough that schools in...

Brought to you by: Hi Reader, Welcome to the Google Sheets Tips newsletter #380, your Monday morning espresso, in spreadsheet form! I read something online last week (source) that really resonated with me: Joy is a competitive superpower The author gave the example of the US figure skater Alysa Liu, who rocked a huge smile on her way to a gold medal at the recent Winter Olympics. As someone who has a tendency to take things too seriously, this was a good reminder for me to smile more and...