How to compare dates or date against today with query on google sheets?

There’s no today() in Query. Use now() instead:

=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M > now() ",0)

Or if you want now() without time(equivalent to TODAY()), use:

todate(now())

For this to work, provided you have all the correct dates in M in any format, which Google sheets recognises (i.e., the formula bar shows the correct date or time) regardless of the actual string. If not, You should manually convert all those remaining dates to correct format. The correct format of date to be entered in the query formula is date 'yyyy-mm-dd'. It doesn’t matter what format the date is in sheets ( as long as Google sheets recognises this), but the actual formula must only contain date in this format for comparison. For example , to find all dates less than 31,August, 2017,

=query(A2:B6, "select A where A < date '2017-08-31'")

You can use this to figure out all the dates, which Google doesn’t recognise: N1:

M:M*1

If you get an error in the helper column N, then those dates are not recognised. Even if you did not get error, it is possible that Google sheets mis-recognizes the date. There is also a more specific function:

=ARRAYFORMULA(ISDATE(M:M))

References:

Leave a Comment