0

Below is the data in csv file in s3 bucket which I have used to build Athena database.

John Wright cricket 25
Steve Adams football 30

I am able to run the query and get the data.

Now I am trying to fetch date of birth based on age column. Is it possible to generate date of birth from age column like current date - age (column) and print only the date of birth?

I tried below query but not sure whether it is correct way

select (current_date - interval age day) from table_name;

Please help me with this.

2
  • You can't transform age in years into full birth date for obvious reason - you can get only the year of birth. Commented Sep 5, 2021 at 17:53
  • You may get year of birth iff age in csv file is calculated based on today's date. Otherwise, you'll endup with wrong year of birth in edge cases. Commented Sep 6, 2021 at 2:51

1 Answer 1

2

You can use the date_add function, like this:

SELECT date_add('year', -age, current_date) FROM table_name

I.e. subtract age number of 'year'(s) from the current date.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I will ty this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.