I posted the message below hoping someone would be able to help - so far nothing!
For sure there must be someone out there that can open the designer, create three numeric boxes, set the objects to be time oriented only, and the last box having the appropriate Java script or FormCalc script to have it show the difference in time.
The script I show below works just great - accept as noted. WHY? What modifications do I need to make to have it work 100% of the time?
<<<< below is the orginal posting on the forum >>>>>>>>>>
The following Java script is entered in as the "total time" calculation formula
"this.rawValue = endingTime.rawValue - beginningTime.rawValue" however when the following times are inserted the calculation accuracy fails.
beginning time: 1430
ending time: 1700
the total time becomes 2:70 rather than 2:30.
The reason seems to be the time format in PM mode is reading as a numeric formula rather than a time formula. Therefore, the subtraction is standard borrowing and carrying (1700 becomes 1600 + 100 + 0) rather than time (1700 becomes 1600 + 60).
Does anyone have a solution?
I have also tried resolving the issue using "FormCalc" but with no success
the accuracy is tottaly correct 1700 -1430 is 270 it is that simple however what your trying to do is subtract the milliseconds of one time from another and convert it back into that many milliseconds divided up into hours and minutes. So calm down and get the formcal refrence manual to help it is poorly written but it is a starting point.
I think you want to do this set both of the fields startDate and EndDate to time/date fields this way you can lock the way information is entered set the display validation and binding patteren to HH:MM then set the binding tab to time from here your final box can be a text field or a date field doesnt matter so much then the easiest way to do this in Livecycle is to use form calc on the total time field
set the script to formcalc and place it under the calculation event.
if(startDate.isNull or endDate.isNull) \\ keep calculation clean
$ = 1 \\incase used with another calculation no errors
I had a lot of trouble with this too, thanks for the help. My solution also adds days for a leave form. The key for me was using the .formattedValue attribute and making sure the binding and value types for the time fields matched "HH:MM". My edit and display formats were "h:MM A".
on the exit event:
if ( HasValue(FromDate) and HasValue(ToDate) and HasValue(FromTime) and HasValue(ToTime) ) then
For many calculations, you need to check that you have the necessary fileds before calculating. For date and time calculations, the exact format of the data string is needed to correctly convert the date. For example Jan 3, 2009 can be written like "01/03/2009" ("MM/DD/YYYY" or 03/01/2009 ("DD/MM/YYYY") and using the wrong formatting string will get you the values for Mar 1, 2009.