1

I have a fruit orchard dataset. One of the columns contain the year the orchard was planted. In another column I would like to have the orchard age. However this pose a problem, since the age changes every year.

My question: Is it possible to auto calculate orchard age based on the year column in postgis? If it is possible, please specify how.

6

Make a view in PostgreSQL, where the age column can be dynamically created using some useful functions:

SELECT date_trunc('month', age(now()::date, '1994-03-19'::date)) AS age;
       age
-----------------
 19 years 5 mons
(1 row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.