Another way of doing so is using database hooks.
You start by defining an age field of type number.
Then, you click on hooks and add an afterQuery hook, at which you calculate the age and set the value to the field.
For instance, it can look something like the following
export function members_afterQuery(item, options) {
// getting the age in milliseconds from epoch
var ageDifMs = Date.now() - item.birthday.getTime();
// milliseconds from epoch
var ageDate = new Date(ageDifMs);
// converting the milliseconds to an age
item.age = Math.abs(ageDate.getUTCFullYear() - 1970);
// we have to return the item when using hooks
return item;
}
The code was taken from StackOverflow