Google-sheets – Dynamic date range query

google sheetsgoogle-sheets-datesgoogle-sheets-query

I'm trying to create two cells that will update my query: A >= date"A1" and A <= date "B1".

My goal is to create a search page for the data, where the end user could insert a date or the =today() function and it would update the query. I am currently getting a formula parse error from:

=QUERY(Data!6:1397,"SELECT A,B,C,D,E,F,G,H,I,J,K,L WHERE A >= date"A1"and
 A <= date"B1"")

Best Answer

Please try:

=Query(Data!A6:L1397,"Select A,B,C,D,E,F,G,H,I,J,K,L where A>=date
 '"&TEXT(A1,"yyyy-mm-dd")&"' and A <= date '"&TEXT(B1,"yyyy-mm-dd")&"'")  

Note Column references for the source data set and that the likes of date '"&TEXT(A1,"yyyy-mm-dd")&"' are to accommodate the possible use of =today().

May be worth mention that the above would be shorter as:

=Query(Data!A6:L1397,"Select * where A>=date '"&TEXT(A1,"yyyy-mm-dd")&"' and 
A <= date '"&TEXT(B1,"yyyy-mm-dd")&"'")