sql - How to get only year from age() function in postgresql select query -


select age(cast(dob date))  mas_patient_details  

when run above query returns

age ---------- 39 years 5 mons 19 days 13 years 2 days 69 years 2 days 41 years 11 mons 25 days 

select age(cast(dob date)) mas_patient_details age <= 59

it returns

39 years 5 mons 19 days 13 years 2 days 69 years 2 days 41 years 11 mons 25 days 

how correct query?

if column fu of data type date, use

select extract(year fu) mydate; 

and if varchar, convert date using to_date()

select extract(year to_date(fu, <your pattern>)) mydate; 

in case:

select extract(year age(cast(dob date)))  mas_patient_details  age <= 59; 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -