• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create a custom calculation script for age in months that doesn't round up

New Here ,
Mar 21, 2023 Mar 21, 2023

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?

Views

735

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2023 Mar 21, 2023

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

Look also at the day of month.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 28, 2023 Mar 28, 2023

Copy link to clipboard

Copied

I honestly have no idea how to do that.  Would you be able to assist me?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2023 Mar 28, 2023

Copy link to clipboard

Copied

LATEST

When does you see 22 months and 28 days?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 28, 2023 Mar 28, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines