I tried the below but none of them work in redshift
datediff(current_date, str_to_date(dob, '%d,-%m-%Y'))/365 as age_today
year(current_date)-year(dob) as age_in_years
The dob is in format 1955-03-20 00:00:00.0
CodePudding user response:
Please mention datepart
in datediff()
function:
datediff(day, dob ,current_date)/365 as age_today
For further read: Redshift datediff function documentation.
CodePudding user response:
I haven't tested this, but how about:
datediff(year, dob, current_date interval '1 year' - interval '1 day') as age
It calculates the difference in years between the birth date and the date in one year (minus one day) to account for partial years. It would handle leap years.