I am trying to calculate an age in x++ where the customer is born on 1/6/2010 to the selected day of his visit - 1/6/2023 today but the result doesn't give me 13 years old but gives me 12.
real ageDiffReal;
int ageDiffInt;
date datetoday = DateTimeUtil::date(Visitas.RFC_DataVisita);
ageDiffReal = (datetoday - mkDate(dir.BirthDay,dir.BirthMonth,dir.BirthYear)) / 365.242199;
ageDiffInt = Round(ageDiffReal,0);
info(strFmt('%1,%2',ageDiffReal, ageDiffInt));
I tried with / 365 and with 365.25 because of leap years but still didn't work well
You're using round(...)
incorrectly.
ageDiffInt = decRound(ageDiffReal, 0); // Better
ageDiffInt = round(ageDiffReal, 1); // Works too
round(...)
- The number that is a multiple of the value specified by the _decimals parameter and is closest to the value specified by the _arg parameter.