These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

I need to add calculated no. of days to a date to get a new date.

KathyMP
Registered: Mar 29 2010
Posts: 6

I am a complete novice. I have read numerous articles to try to get the answer to my query and feel more confused than when I started... I feel overwhelmed by Java Script!

I am trying to create a calculation in an Acrobat 9.0 form which works out a payment date based on an inception date, the number of agreed payments and the overall time period. i.e.:
DueDate1 = "if Payments is more than 0, then add Calc1 [which is number of days between installments] to Inception else leave this field blank".

Once I sort this, I'll need to move onto:
DueDate2 = if Payments is more than 1, then add Calc1 to DueDate1 else leave this field blank".
Etc. up to DueDate11

Based on one article I saw, I put in the following in my DueDate1 field using the Custom Calculation Script:

var nPayments = this.getField("payments").value;
if( nPayments > 0)
event.value = nCalc1 + nInception;
else
event.value = 0;

Absolutely nothing happens. No error messages. Nothing.

Additional info on text fields involved:
Payments = the number of installments that will be paid and is formatted as a number
Months = how long the Installment agreement will last
Calc1 = is the result of Payments / Months * 30 to give me how much time to add to each installment date and is formatted as a number
Inception = the start date of the Installment plan, the date the deposit is paid and is formatted as a date.
DueDate1 = where I want to calculation to happen and is formatted as a date

Because there is a date involved and I'm adding a number to it to get a new date, do I need to change the date to milliseconds? If so, how?

Help!

Kathy

My Product Information:
Acrobat Pro 9.0, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi KathyMP,

Have you read the series Working With Date and Time in Acrobat JavaScript in the Learning Center? Those articles cover all the basics and if you are developing forms with date and time features you should definitely read them and try out the examples. There is a downloadable PDF with just what you want to do- it is a matter of you spensding the time to implement this on your form.

Part 1 is here-
http://www.acrobatusers.com/tutorials/2006/date_time_part1


Hope this helps,

Dimitri
WindJack Solutions
www.pdfscirpting.com
www.windjack.com
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
And what product, Acrobat or LiveCycle Designer, are you using?

Have you looked at Acrobat's JavaScirpt Console for any errors?

[url=http://www.acrobatusers.com/tutorials/2006/javascript_console]The Acrobat JavaScript Console (Your best friend for developing Acrobat JavaScript)[/url] and [url=http://www.acrobatusers.com/tutorials/why-doesnt-my-script-work]Why doesn't my script work?[/url] by Thom Parker

You can add statements to display variables as your code runs by either writing to the Acrobat JavaScript console or by using the 'app.alert()'.

console.show(); // open consoleconsole.clear(); // clear the console messages var sInception = this.getField('inception').value; // inception date as 'mm/dd/yyyy'console.println('sInception: ' + sInception); // show inception date var oInception = util.scand('mm/dd/yyyy', sInception); // convert to date objectconsole.println('oInception: ' + oInception); // display inception object var nInception = oInception.getTime(); // get value of inception date as a numberconsole.println('nInception: ' + nInception); var Payments = this.getField("payments").value;console.println('Payments: ' + Payments); // display nPayments value var Months = 12;console.println('Months: ' + Months); // display months var nCalc1 = Payments / Months * 30;console.println('nCalc1: ' + nCalc1); // display nCalc1 if( nPayments > 0) { console.println('nPayment > 0: ' + (nPayments > 0) );console.println('nCalc1 + nInception: ' + (nCalc1 + nInception) );var oNext = new Date(nCalc1 + nInception)console.println(oNext); event.value = util.printd('mm/dd/yyyy', oNext);} else { console.println('nPayment > 0: ' + (nPayments > 0) ); event.value = '';}

George Kaiser

KathyMP
Registered: Mar 29 2010
Posts: 6
Hi Dimitri and gkaiseril, Thanks for your efforts. I'm afraid this stuff is just over my head. I can read and understand the articles up until they get to the actual script and then my head starts swimming. I've spent the entire day trying to get some semblance of understanding this stuff out and am no closer. I'll have to find another way. Thaks anyway.

Kathy