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 -

c# SetCompatibleTextRenderingDefault must be called before the first -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -