A have a table where Column A has dates. I want to get all values of a specific month

I have the following query for May for example

=query(Database!A1:AD,"Select A,E,F,U,V,W,X,AB,AC where Month(A) = 5",1)

but it does not work. Where I am wrong? Query

=query(Database!A1:AD,"Select A,E,F,U,V,W,X,AB,AC where A > date '2019-05-01' and A < date '2019-05-31'",1)

works fine but I have a separate drop-down list with the months' number 01 02 03 .... and I want the query to change when I change the month number. But even when I put the month number directly into query it shows nothing. No any mistake - just no rows with values, only header

  • can you share a copy of your sheet? – user0 May 21 '19 at 21:27
  • months in QUERY starts from 0 so you need to fix it with +1

    =QUERY(Database!A1:AD, "select A,E,F,U,V,W,X,AB,AC where month(A)+1 = 5", 1)

  • Just found out that! Thanks. Now how can I change 5 to a link to the specific cell with a drop-down list? when I try =query(Database!A1:AD,"Select A,U,V,W,X,AB,AC where E = '"&B1&"' AND Month(A)+1 = '"&D1&"'",1) it does not work – Marchuk Anton May 21 '19 at 21:37
  • Here I created a copy of the sheet docs.google.com/spreadsheets/d/… – Marchuk Anton May 21 '19 at 21:38
  • like this: =query(Database!A1:AD,"Select A,U,V,W,X,AB,AC where E = '"&B1&"' AND Month(A)+1 = "&D1,1) – user0 May 21 '19 at 21:45
  • thanks, now works fine – Marchuk Anton May 21 '19 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.