Search code examples
dategoogle-sheetsgoogle-sheets-formulagoogle-query-language

Query and Today Function


This formula should filter all results between today and 7 days from now from another sheet but it gives a Formula parse error:

=QUERY(Sheet2!A3:H13;"SELECT A, B, C, D, E, F, G, H WHERE (A >= date '"&text(TODAY(),"yyyy-MM-dd")&"' AND A <= date '"&text(TODAY()+7,"yyyy-MM-dd")& "')"; false)

If I use this formula instead:

=QUERY(Sheet2!A3:H13;"SELECT A, B, C, D, E, F, G, H WHERE (A >= date '2020-11-08' AND A <= date '2020-11-15')"; false)

It works but it would need to change dates manually everytime. Where I am wrong?


Solution

  • try:

    =QUERY(Sheet2!A3:H13;
     "where A >= date '"&TEXT(TODAY();   "yyyy-MM-dd")&"' 
        and A <= date '"&TEXT(TODAY()+7; "yyyy-MM-dd")&"'"; 0)