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

Date/Time feild subtraction Designer 7????

beachbumbali11
Registered: Mar 5 2008
Posts: 74

Thanks so much to this lovely forum I am learning so much from here, I got the java script time date calculation from the samples here works great in Acrobat, however i want to expand the capabilities of my forms so I am trying to use designer 7 to use subforms that auto generate fields. got that to work but the date script wont work in designer can any one help?
Here is the script i am trying. I think the error is with the last line event but not sure.
So my question is this what's the script and where do I place it initilize or calculate i just want one date to subtract from the other

var strStart = this.getElement("requestDateIn").value;
var strEnd = this.getElement("requestDateOut").value;
if(strStart.length||strEnd.length)
{
var dateStart = util.scand("DD-MM-YY",strStart);
var dateEnd = util.scand("DD-MM-YY",strEnd);
var diff = dateEnd.getTime() - dateStart.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
event.value = days;
}

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Because of the first two lines I'm assuming that this is a calculation script on a subform? This is quite a novel approach. The "getElement" function is for acquiring an XML subnode, and I don't thing it will work. You're much better off simply referring to the fields using the regular syntax.

The correct location for this script is the calculation event for result field.

The main problems for the script above is that you are mixing AcroForm and LiveCycle syntax. For example, the value of a field is acquired with the "rawValue" property, and the result of a calcualtion is return from the last evaluated statment in a calculation script. There is no need to do a direct assignment. "event.value" has no meaning in LiveCycle, but the script should still work because this is the last statment evaluated.

Your time calculations are correct as long as the date formats are correct.

Try this:

if(requiestDateIn.rawValue.length || requestDateOut.rawValue.length)
{
... Time Caculation based on the "rawValue" ...

this.rawValue = days;
}

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script