To calculate the age of a person from a give DOB, add a Formula field and specify the formula expression as given below:
((zoho.currentdate - DOB) / (1000 * 3600 * 24 * 365)).round(2)
Note: If you use a Formula field, the calculated age can be seen only in the View (i.e) the calculation is done after Form Submit. But, if you use a Number field the Age can be displayed in the Form itself before Submit. This is achieved by adding On user input script to the number field. Refer the sample application named Age Calculation which uses both the Formula Field (Age2) and a Number Field (Age), to calculate age.
Given below is the Deluge script of the form (FormA) which has both the number field (Age) and the formula field (Age2) to calculate age. You can also view the script from the Script tab, by copying the sample application to your account. Use More Actions -> Copy application to copy the application to your account.
form FormA
{
Name
(
type = text
)
DOB
(
type = date
on user input
{
if (input.DOB != null)
{
input.Age = ((zoho.currentdate - input.DOB) / (1000 * 3600 * 24 * 365)).round(2);
}
}
)
Age
(
type = decimal
width = 20
)
Age2
(
type = formula
value = ((zoho.currentdate - DOB) / (1000 * 3600 * 24 * 365)).round(2)
)
}