jugstalt / gview-gis

gView GIS - Userfriendly open source GI framework
Apache License 2.0
8 stars 4 forks source link

Filter expression with Date criteria? #28

Open faulgurke opened 4 months ago

faulgurke commented 4 months ago

What is the syntax for filtering with Date criteria? I want to filter records with the current year but can not figure out how it works. Example: Column with years in integer format. Filtering criteria is the current year.

jugstalt commented 4 months ago

To filter records with the current year in a PostgreSQL database where you have a column containing years in integer format, you can use the EXTRACT function to get the current year from the current date. Below is an example of how to write the SQL WHERE clause:

SELECT *
FROM your_table_name
WHERE year_column = EXTRACT(YEAR FROM CURRENT_DATE);

or with SQL Server:

SELECT *
FROM your_table_name
WHERE year_column = YEAR(GETDATE());

In this example, EXTRACT(YEAR FROM CURRENT_DATE) extracts the current year from the current date and returns it as an integer. This integer is then used to filter the records in the year_column.

In a gView.Carto Query Filter:

year_column = EXTRACT(YEAR FROM CURRENT_DATE)