1 person found this helpful
First, date are specialaly formatted character stirngs and need some special processing before being able to use them in any computation. One uses the 'Date2Num()' function of FormCalc to extract the number of days from a given date string. One needs to be careful to make sure the date string is in the expected format. The best method is to use the 'formattedValue' of a field to get the string in the expected format. The number of days is the difference from the Epoch date. You will need to get this value for each date. Then you subtract the start date from the end date and add 1 to get the difference in days between the 2 dates. You can divide the difference in days by 365.25 to obtain the number of years and then use the 'Floor()' function to obtain the whole number or years.
Thanks for the quick reply and the thoroughness of the information. I had written almost the entire script, however the "+1" seems to have made all the difference. It now works perfectly.
Sorry, I originally flagged your response as Helpful, not Answered... if there is any way to correct this please let me know.
Next question: how do I get the calculated field to remain empty until the source fields are filled out?
FormCalc has a 'Has Value()' function that returns 'true' only when the field has been updated, so you can add an if statement that uses the 'Has Value()' function for both of the fields and only returns a true result when both fields have data.
I need an age in months and years.
On my LiveCycyle form I have two date fields 'dob' and 'rdtestdate'. I am in Australia so we use dd/mm/yyyy as the format.
The field designated to display the calculated result -- 'rdage' -- is set as a calculated-read only text field.
I've been studying and testing the various solutions but don't understand well enough, sorry! When I paste in a sample and change the field names to match mine, my result remains empty. Sometimes I get a failed script message as I try to save the form. I've tried quite a few different scripts to no avail.
Thanks for any assistance.