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

Date Calculation

realname
Registered: Aug 15 2008
Posts: 93
Answered

I have been trying to do a date calculation in my form and cannot seem to get it to work. I have searched through the forums and have found what seemed to be solutions, however, they also have not worked. I can't seem to get the scripts that I've found to function and believe that maybe I am not referencing my fields in livecycle correctly. The following script is directly from this link:

http://www.acrobatusers.com/tech_corner … ime_part1/

var strEnd = this.getField("DateEnd1").value;
if(strStart.length && strEnd.length)
{
var dateStart = util.scand("mmm d, yyyy",strStart);
var dateEnd = util.scand("mmm d, yyyy",strEnd);
var diff = dateEnd.getTime() - dateStart.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
event.value = days;
}
else
event.value = 0;

This is exactly what I'm trying to do but don't know where I am going wrong.

My fields are date/time fields and the calculation I am trying to do is:

CessionTo - CessionFrom = No. of Days

Can anyone help?

Thanks in advance!

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Have you downloaded and saved the sampel form so that you can look at the scirpt?

If you carefully read the how to article it is for using Acrobat JavaScript and the form is an Acro From not a LiveCycle Designer form. One can not just cut and past Acro Forms JaavaScirpt inot LiveCuycle Designer.

LiveCycle Designer has a number of functions available to FormCalc. You can use the "Date2Num()" function to get the number of day since the Epoch date for a given date string and matching format string.

Have you loooked at [url=http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=13175]Date Subtraction Live Cycle continued[/url]?

You will have to adjust the field names and format strings to match your particular situtation.

George Kaiser

realname
Registered: Aug 15 2008
Posts: 93
Thank you, it finally worked using FormCalc. As for the javascript that I tried, I did modify the script to fit my form but had no success.

After a few trials and errors with FormCalc however, it seemed the problem was the formatting was not the same.

Thank you for your help.