Skip to content
Advertisement

how to find Age from DOB in Athena?

Here is my query to find out age from the DOB column :

date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age

I am getting following error:

SYNTAX_ERROR: line 4:47: ‘-‘ cannot be applied to varchar, varchar

Appreciate your help!

Advertisement

Answer

You should be able to solve this using function DATE_DIFF(). From the documentation:

date_diff(unit, timestamp1, timestamp2)bigint

Returns timestamp2 - timestamp1 expressed in terms of unit.

Try:

DATE_DIFF('year', c.memberdob, current_timestamp) as age
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement