Skip to main content
Participant
April 27, 2018
Answered

Calculated age from a filled field

  • April 27, 2018
  • 1 reply
  • 716 views

How can i calculate age in a form based on the birth date that the user will input?

This topic has been closed for replies.
Correct answer gkaiseril

You will need to use JavaScript for the calculation.

The process is to convert the date string to a JavaScript date object using the util.scand method. You will also need to get the system date into a JavaScript date object. From the 2 date objects you can either get the number of milliseconds form the Epoch date for JavaScript, compute the difference, and then convert to the number of years. Or you can use the date object's methods to get the full year, month, and dates from the 2 date objects and then do the needed math to compute the number of years, months and days as needed.

This question has been asked many times and many solutions have been posted. Please use the search tool for this form to locate them.

1 reply

gkaiserilCorrect answer
Inspiring
April 27, 2018

You will need to use JavaScript for the calculation.

The process is to convert the date string to a JavaScript date object using the util.scand method. You will also need to get the system date into a JavaScript date object. From the 2 date objects you can either get the number of milliseconds form the Epoch date for JavaScript, compute the difference, and then convert to the number of years. Or you can use the date object's methods to get the full year, month, and dates from the 2 date objects and then do the needed math to compute the number of years, months and days as needed.

This question has been asked many times and many solutions have been posted. Please use the search tool for this form to locate them.