Automatically calculate age from a date in collection

I have a collection of hundreds of location (buildings) with a year of construction and id like to have the “age” calculating itself automatically, in the DB if possible.

Those location are in a TABLE in column, and i need te age hcolumn to be sortable,too. And it will have ‘years’ on the side ex; 109 Years, but i dont know how to sort in numerical order if there is letter too…

I made that post here long ago… still the smae thing.

Hello,

Depending on how you are inserting these locations there are a couple ways to do this.

If you are uploading the locations through a form:

  • Create an afterInsertHook that gets the year of the location, calculates its age based off of this year, and concatenates that value with ‘Year(s)’

If you are uploading the locations manually:

  • Create a excel sheet that does this, and when you added all of them just import it into the collection using the import method

Goodluck!
Majd

Sorry, im not sure if we are on the same page on what i try to do.

The locations are already in the database, the years are already in a culumn and there is a column for age too, awaiting to be filled with the calculations from the construction year.

I read about the first option you gave me but i dont understand how it can calculate the year base on date and put it in the good row.

How will the table will understand to sort it the good way if there is text with the numbers?
If there is letters with the numbers it will sort like that : 1, 112, 14, 183 … like not really in the good order but like all the 1 together, all the 2 together, etc.

Sorry for my english