Hi,
I have recieved a job where I need to calculate the number of years a customer has been a member of a club and use this as a variable text in a greeting-card. With the records (txt-file) there is a column that contains the member start date. I only need to calculate the years from member start year to the current year.
is this possible to do in the datamapper or in workflow?
Has anybody done this and have a nice solution ready?
I found the following on the web and used it in OL Connect Designer:
function calculateAge(birthday) { // birthday is a date
var ageDifMs = Date.now() - new Date(birthday);
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
results.text( calculateAge( record.fields.bd ) );
Hope this helps,
Erik
Implemented the same logic in Data Mapper, see the attached data mapper config file.
age.OL-datamapper (3.2 KB)
Erik
Thank you Erik for your time and effort, I will certainly try this at my end.