QGIS – Selecting Features by Expression

select-by-expression

I have a set of features in a single layer that have been created during various periods of time.

In a layer attribute table, there is a column kreirao_datum which means created on a date

In a layer attribute table, there is a column kreirao_datum which means created on a date

I would like to select all features created within a single calendar year, for example 2021, using 'Select by Expression', but I can not figure out how to write the expression.

It should probably be something like "kreirao_datum" = '2021-07-29T09:45:01.000', and it works for a single matching record.

But how can I write expression that would select all records created within a 2021 year, "kreirao_datum" = '2021_????'?

enter image description here

I am very well aware that I can use Filter within attribute table, and it also works, but I am trying to determine what would be the right expression for 'Select by Expression'.

Best Answer

Use function year() to extract the year form your date:

year ("kreirao_datum") = 2021

enter image description here