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

sum dates

cagdas
Registered: Jan 6 2008
Posts: 7

hi everbody,

i am trying to create form that; first field is "value date" and the second field is "maturity date" (this are in date format) and at the end third field will be = "value date" - "maturity date" and i want this third field will be in number format and can be calculate the days difference field1 and field2.

appreciate your kind answer.

thanks and regards
Caci

My Product Information:
Acrobat Pro 8.1.1, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Date arithmetic is possible with both Acrobat Forms and LiveCycle Designer. In general one has to convert the date strings into a number and then perform the calculation on the resulting number and maybe do some conversion to get to the number of days.

From the Acrobat JavaScript documentation:

/* Example of date arithmetic. */
/* Create a Date object with a definite date. */
var d1 = util.scand("mm/dd/yy", "4/11/76");
/* Create a date object containing the current date. */
var d2 = new Date();
/* Number of seconds difference. */
var diff = (d2.valueOf() - d1.valueOf()) / 1000;
/* Print some interesting stuff to the console. */
console.println("It has been " + diff + " seconds since 4/11/1976");
console.println("It has been " + diff / 60 + " minutes since 4/11/1976");
console.println("It has been " + (diff / 60) / 60 + " hours since 4/11/1976");
console.println("It has been " +
((diff / 60) / 60) / 24 + " days since 4/11/1976");
console.println("It has been " +
(((diff / 60) / 60) / 24) / 365 + " years since 4/11/1976");

The above code will work in Arcbat Forms and LiveCycle Designer. For your application, you will need to pass the value of the fields and Acrobat Forms and LiveCycle Designer have a different syntax to reference the field and value. Note that the format of the displayed field is needed to generate the date object. JavaScript uses the date value in milliseconds.

LiveCycle Designer can use some built in functions to simplify the task

$.rawValue = Date2Num(maturity_date.formattedValue, "M/D/YYYY") - Date2Num(value_data, "M/D/YYYY")

LiveCycle use days for the result of the conversion to a number.

George Kaiser

cagdas
Registered: Jan 6 2008
Posts: 7
Thanks very much gkaiseril. I will try your solutions immediately..