+3 votes
in Databases by (4k points)
I have a PostgreSQL table wherein one column has date of birth. I need to extract year from date of birth. How can I do?

e.g. I want to get 1980 from 1980-03-04.

1 Answer

0 votes
by (17.9k points)
edited by

You can use the extract() function as follows:

SELECT EXTRACT(YEAR FROM colum_name) FROM table

The above query will give you the year from your date column.

You can also use date_part() function to get year, month, day, hour, minute, second from a timestamp.

SELECT date_part('year', column_name) FROM table

...