← servoy magazine

[Tip] Calculate Age

  • Tips

by Jan Aleman
Servoy

//the tip assume birthdate in the variable/column birthdate
var theage = utils.dateFormat(new date(), 'yyyy') - utils.dateFormat(birthdate, 'yyyy')

//if the birthdate has not passed substract a year
if (utils.dateFormat(forms.id.id_birthdate, 'MM') >= utils.dateFormat(abc_date,'MM'))
{
    if (utils.dateFormat(forms.id.id_birthdate, 'd') > utils.dateFormat(abc_date, 'd'))
    {
        abc_age--
    }
}