I have an age on the format 57 years 5 months 7 days, and I want to deduct the date of birth from it in postgresql on a format like yyyy-mm-dd, how do I do that?
I have an age on the format 57 years 5 months 7 days, and I want to deduct the date of birth from it in postgresql on a format like yyyy-mm-dd, how do I do that?
We can get the past date using multiple intervals. I added a couple examples to the data to check that it's working.
select *
,current_date + (interval '-1 years'*years) + (interval '-1 month'*months) + (interval '-1 day'*days) as dte
from t
| years | months | days | dte |
|---|---|---|---|
| 57 | 5 | 7 | 1965-04-18 00:00:00 |
| 36 | 11 | 12 | 1985-10-13 00:00:00 |
| 6 | 2 | 1 | 2016-07-24 00:00:00 |