3

I am using QGIS.

I want to filter for all datapoints that were taken over a specific period: 01/01/2015 to 31/12/2015. If I use the 'filter features using form' I can manage this, however I wanted to do it in the Query Builder.

This is the Specific Filter Expression I use:

"Date">'01/01/2015' AND "Date"<'31/12/2015'

(As "Date" is the field column in my data sheet)

When I submit this however, in addition to the second filter I am applying ("Label", and I have no issue with this filter), I find that the date filter has been completely disregarded, and my data is only filtered by "Label".

How do I filter for a specific date duration?

1
  • 2
    You could start by using ISO 8601 date representation - YYYY-MM-DD (ob xkcd). This assumes that the Date column is an actual date type. Otherwise it's just a string comparison, and the results are randomized by failure to use ISO 8601.
    – Vince
    Jul 31 at 16:39
5

As @Vince already mentioned, this is not a date but a string. You need to convert it to a date first, then you can do the comparison. You can use to_date() function in field calculator like:

to_date('01/01/2015','dd/MM/yyyy')

so your expression would look something like:

"Date">to_date('01/01/2015','dd/MM/yyyy') AND "Date"<to_date('31/12/2015','dd/MM/yyyy')

Note that this of course also will only work if your Date field is actually a date and not just another string. If it is a string as well, you need to convert it to a date first in the same way. E.g.

to_date("Date",'dd/MM/yyyy')>to_date('01/01/2015','dd/MM/yyyy') AND to_date("Date",'dd/MM/yyyy')<to_date('31/12/2015','dd/MM/yyyy')
0

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.