Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
in the future, to find the best place to post your message, use the list here, https://community.adobe.com/
p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post if it helps you get responses.
<moved from using the community>
Copy link to clipboard
Copied
Look also at the day of month.
Copy link to clipboard
Copied
I honestly have no idea how to do that. Would you be able to assist me?
Copy link to clipboard
Copied
When does you see 22 months and 28 days?
Copy link to clipboard
Copied
This isn't an issue of rounding at all. Your code has to do what YOU would do in giving the child's age. For example. The child was born in January. It is 20 July. How old are they? Can YOU answer that question? Or do you need more info? And, if you need more info, what EXACTLY do you do with it? The code has to match what a human would do.