How can I calculate the age of a person from a given Date of Birth?

How can I calculate the age of a person from a given Date of Birth?

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)
)
}
    • Related Articles

    • How can I calculate the number of days between two date fields?

      To calculate the number of days between two given date fields, for instance, ServiceStartDate and ServiceEndDate, add a formula field to the form with formula expression as below. ((ServiceEndDate - ServiceStartDate) / (1000 * 60 * 60 * 24)) ,where ...
    • Date-field Autoresponder

      Understanding date-field autoresponder Date-field based autoresponders are a series of automated messages that are sent to contacts based on the date in the date field associated with them. Wishing customers happy birthdays and anniversaries are ...
    • How can I restrict entries to my Registration Form based on a given date?

      Assume you have a Registration form to register for a specific course and the registration is open till 30th Dec 2009. To restrict entries from being submitted after this date, use the zoho.currentdate variable within the on add -> on validate block ...
    • How can I calculate the number of hours between two date and time fields?

      To calculate the number of hours between two date and time fields, add a formula field and specify the formula expression as ((To_Date - From_Date) / (1000 * 60 * 60))   form Sample { FromDate ( type = datetime ) ToDate ( type = datetime ) Hours ( ...
    • Is it possible to obtain month and day information from a given date field?

      Yes, you can use the Deluge date function getDay() and getMonth() to obtain the day and month information. - getDay() returns the numerical day of the month for a particular year. The value returned will be between 1 and 31. - getMonth() returns the ...