How to get the current year in PostgreSQL?

by diana_barrows , in category: SQL , 2 years ago

How to get the current year in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by ewald , 2 years ago

@diana_barrows Use date_part() function to get the current year in postgresql, query as example:

1
2
-- Output: 2022
SELECT date_part('year', now());


by hortense_donnelly , 10 months ago

@diana_barrows 

You can get the current year in PostgreSQL using the EXTRACT() function and the year unit. Here's an example:


SELECT EXTRACT(year FROM CURRENT_DATE);


This will return the current year in four-digit format (e.g. 2021).