I need to see only the current year rows from a table.
Would it be possible filter a timestamp column only by current year parameter, is there some function that can return this value?
SELECT * FROM mytable WHERE "MYDATE" LIKE CURRENT_YEAR
I need to see only the current year rows from a table.
Would it be possible filter a timestamp column only by current year parameter, is there some function that can return this value?
SELECT * FROM mytable WHERE "MYDATE" LIKE CURRENT_YEAR
In PostgreSQL you can use this:
SELECT * FROM mytable WHERE date_part('year', mydate) = date_part('year', CURRENT_DATE);
The date_part function is available in all PostgreSQL releases from current down to 7.1 (at least).
This is pretty old, but now you can do:
SELECT date_part('year', now()); -> 2020
In the place of now you can pass any timestamp. More on Documentation
I prefer this writing
SELECT EXTRACT(YEAR FROM CURRENT_DATE) AS year;
So your query would be:
SELECT * FROM mytable WHERE "MYDATE" = EXTRACT(YEAR FROM CURRENT_DATE);