Dear All,
I have been utilising the calculation found on Wix for calculated data elements and I have followed the steps and copied the code and it constantly create an error within the Data Collection I am having difficulties with understanding why? I have placed this in the data.js file as suggested. any help would be greatly appreciated. @yisrael-wix
import wixData from ‘wix-data’;
export function Details_afterQuery(item, context) {
item.age = ageFromDob(item.dob);
return item;
}
function ageFromDob(dob) {
const now = new Date();
const days = now.getDate() - dob.getDate();
const months = now.getMonth() - dob.getMonth();
let age = now.getFullYear() - dob.getFullYear();
if (months < 0 || (months === 0 && days < 0)) {
age–;
}
return age.toString();
}