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

How to get the arclen between two curve points in Maya? -

C++ Linked List -

git svn - Unignore directories in git-svn (adding directories to a sparse checkout) -