# Adobe LiveCycle how to calculate time difference

I have a livecycle form with two time fields and a textbox; I am trying to do a calculation between the two time fields.  I have the following code in the formCalc but it will not calculate:

// get end time in milliseconds from the Epoch date
var EndTime = Time2Num(SatTimeOut1.formattedValue, "HH:MM")
// get start time in milliseconds from Epoch date
var StartTime = Time2Num(SatTimeIn1.formattedValue, "HH:MM")
// compute difference in milliseconds
var Diff = EndTime - StartTime
// difference in seconds
Diff = Diff / 1000
// difference in minutes
var Minutes = Diff / 60
// difference in hours
var Hours = Minutes / 60
// Get whole hours only
Hours = Floor(Hours)
// Get minutes only (modulo 60 of minutes)
Minutes = Mod(Minutes, 60)
// format the result
Concat(Hours, ":", Format("99", Minutes))

When I preview the PDF is shows 0:00 in the text field no matter what value is entered in the time fields.

Any help would be greatly appreciated...
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You need to wrap the Time2Num() function inside the TimeDiff() function as illustrated below from this link:
http://acrobatusers.com/forum/javascript/time-subtraction/

For the LiveCycle Desinger assuming the start and end times are within the same day, the following script will compute the difference in hours and minutes and format the display into hours and minutes using the format of 'h:MM A":

if( HasValue(EndTime) & HasValue(StartTime) ) then
// compute time difference in minutes
var TimeDiff = (Time2Num(EndTime.formattedValue, "h:MM A") - Time2Num(StartTime.formattedValue, "h:MM A")) / (1000 * 60)
// truncate to hours
var HourDiff = Floor(TimeDiff / 60)
// get minutes less than 60
var MinDiff = Mod(TimeDiff, 60)
// build fomatted dispaly string
Concat( Format("Z9", HourDiff), ":", Format("99",MinDiff) )
else
// if any values missing null the output
null
endif

Experts Exchange Solution brought to you by