Filter layer to show features from -180 to -90 days from today

You can do it with a Virtual Layer in QGIS. It works on a shapefile, so it must also works on a FileGeodatabase since a virtual layers uses a generic SQLite syntax.

select * 
from mytable 
where ANDRING_DA > date('now', '-180 day') AND ANDRING_DA < date('now', '-90 day')

In general it is pretty dirty using a FileGeodatabase in QGIS, compaired to other of the dataformats available.

More on time functions in SQLite: https://www.sqlite.org/lang_datefunc.html


Another solution by means of "Function Editor" via "Select Features by Expression"

tab1

Use the following function

import datetime
from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def seldate(start, stop, feature, parent):
    base = datetime.datetime.today()
    date_list = [(base - datetime.timedelta(days=x)).strftime("%d.%m.%Y") for x in range(start, stop)]
    return date_list

This function will give you a list:

['02.05.2020', '01.05.2020', '30.04.2020', '29.04.2020', '28.04.2020', '27.04.2020', '26.04.2020', '25.04.2020', '24.04.2020', '23.04.2020', '22.04.2020', '21.04.2020', '20.04.2020', '19.04.2020', '18.04.2020', '17.04.2020', '16.04.2020', '15.04.2020', '14.04.2020', '13.04.2020', '12.04.2020', '11.04.2020', '10.04.2020', '09.04.2020', '08.04.2020', '07.04.2020', '06.04.2020', '05.04.2020', '04.04.2020', '03.04.2020', '02.04.2020', '01.04.2020', '31.03.2020', '30.03.2020', '29.03.2020', '28.03.2020', '27.03.2020', '26.03.2020', '25.03.2020', '24.03.2020', '23.03.2020', '22.03.2020', '21.03.2020', '20.03.2020', '19.03.2020', '18.03.2020', '17.03.2020', '16.03.2020', '15.03.2020', '14.03.2020', '13.03.2020', '12.03.2020', '11.03.2020', '10.03.2020', '09.03.2020', '08.03.2020', '07.03.2020', '06.03.2020', '05.03.2020', '04.03.2020', '03.03.2020', '02.03.2020', '01.03.2020', '29.02.2020', '28.02.2020', '27.02.2020', '26.02.2020', '25.02.2020', '24.02.2020', '23.02.2020', '22.02.2020', '21.02.2020', '20.02.2020', '19.02.2020', '18.02.2020', '17.02.2020', '16.02.2020', '15.02.2020', '14.02.2020', '13.02.2020', '12.02.2020', '11.02.2020', '10.02.2020', '09.02.2020', '08.02.2020', '07.02.2020', '06.02.2020', '05.02.2020', '04.02.2020', '03.02.2020']

Or if you prefer sorted then:

['03.02.2020', '04.02.2020', '05.02.2020', '06.02.2020', '07.02.2020', '08.02.2020', '09.02.2020', '10.02.2020', '11.02.2020', '12.02.2020', '13.02.2020', '14.02.2020', '15.02.2020', '16.02.2020', '17.02.2020', '18.02.2020', '19.02.2020', '20.02.2020', '21.02.2020', '22.02.2020', '23.02.2020', '24.02.2020', '25.02.2020', '26.02.2020', '27.02.2020', '28.02.2020', '29.02.2020', '01.03.2020', '02.03.2020', '03.03.2020', '04.03.2020', '05.03.2020', '06.03.2020', '07.03.2020', '08.03.2020', '09.03.2020', '10.03.2020', '11.03.2020', '12.03.2020', '13.03.2020', '14.03.2020', '15.03.2020', '16.03.2020', '17.03.2020', '18.03.2020', '19.03.2020', '20.03.2020', '21.03.2020', '22.03.2020', '23.03.2020', '24.03.2020', '25.03.2020', '26.03.2020', '27.03.2020', '28.03.2020', '29.03.2020', '30.03.2020', '31.03.2020', '01.04.2020', '02.04.2020', '03.04.2020', '04.04.2020', '05.04.2020', '06.04.2020', '07.04.2020', '08.04.2020', '09.04.2020', '10.04.2020', '11.04.2020', '12.04.2020', '13.04.2020', '14.04.2020', '15.04.2020', '16.04.2020', '17.04.2020', '18.04.2020', '19.04.2020', '20.04.2020', '21.04.2020', '22.04.2020', '23.04.2020', '24.04.2020', '25.04.2020', '26.04.2020', '27.04.2020', '28.04.2020', '29.04.2020', '30.04.2020', '01.05.2020', '02.05.2020']

And afterwards paste this array_contains(seldate(90,180), "ANDRING_DA") into "Expression"-tab

tab2

Tags:

Qgis