I am using QGIS Essen version (2.14.1). I am trying to filter my data based on dates. I am wondering if the "between" operator exists like in SQL? I'm trying the following query but the results are wrong. Or is it the date format which is a problem?

(("all_ws_d_2"  <= '01-09-16') and  ("all_ws_d_3"   >=   '30-09-16'))
or (("all_ws_d_2"  >=  '01-09-16') and ("all_ws_d_3"  <= '30-09-16'))
or (("all_ws_d_2" <=  '01-09-16') and (("all_ws_d_3"   => '01-09-16') and ("all_ws_d_3"   <=  '30-09-16' )))
or (("all_ws_d_2" >= '01-09-16') and  (("all_ws_d_2"  <=   '30-09-16') and ("all_ws_d_3"  >=  '30-09-16')))
  • Your date format is probably wrong. See this post: How to enter a date into the attribute table?. It should be "YYYY-MM-DD". By the way, I don't think there is a native between operator, but you can create a custom Python function. – ArMoraer May 11 '16 at 10:23
  • @ArmoraerThanks it might be that, do you know how I can automatically change the format of my dates in QGIS, instead of doing a join from Excel? – philippe May 11 '16 at 10:33
  • There's a thread here with a couple of exampes of using the field calculator that I think does what you're after gis.stackexchange.com/questions/111209/date-format-conversion – Ed Rollason May 11 '16 at 10:56
  • Thanks! now i am getting the following error message, any ideas? OGR [3] erreur 1: Type mismatch or improper type of arguments to <= operator. – philippe May 11 '16 at 11:07

Your Answer

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

Browse other questions tagged or ask your own question.