Nick_Nick
Nick_Nick

Reputation: 51

Display Date on Years Only PGSQL

I have this SQL query, and I want to display only the years. How can I do it? I'm getting years, months, days, and hours. Thank you.

SELECT date_of_birth, AGE(now(), date_of_birth) AS age
FROM students
ORDER BY age DESC

Output: enter image description here

Upvotes: 0

Views: 20

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269573

You can use extract():

 select extract(year from AGE(now(), date_of_birth))

Upvotes: 1

Related Questions