Question
Create a custom calculation script for age in months that doesn't round up
I am trying to fix a PDF form to calculate a child's age in months. I have been trying to use the below custom calculation script
var cDateFormat = "yyyy-mm-dd";
var cDate = this.getField("dob").value;
if (cDate != "") { var oDate = util.scand(cDateFormat, cDate); }
if (oDate == null) app.alert("Invalid date: " + cDate, 1, 0);
else {
var now = new Date();
var nMonth = Number(now.getMonth());
var nYear = Number(now.getFullYear());
var diffYear = nYear - oDate.getFullYear();
var diffMonth = nMonth-oDate.getMonth();
if (diffYear) { diffYear = diffYear * 12; }
event.value = diffMonth + diffYear;
}
How do I change this formula so that I don't have the month rounding up? This current formula will make 22 months 28 days into 23 months, and I need it to stay at 22 months?
Is there a way to fix this formula to eliminate the rounding up to the next month?
