Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Adobe LiveCycle how to calculate time difference

Posted on 2012-04-11
Medium Priority
2,815 Views
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...
0
Question by:NCSO
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 38

Accepted Solution

puppydogbuddy earned 2000 total points
ID: 37836009
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
0

LVL 38

Expert Comment

ID: 37836022
oops! You don't need to use the TimeDiff function.  You just need the Time2Num() function to compute the time differential.
0

Author Closing Comment

ID: 37851445
Many Thanks!  Great to have a resolution...
0

Expert Comment

ID: 40065115
I tried puppydogbuddy's scripts but still got 0:00 no matter what I entered in the time fields. Could anyone please help? Thanks!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update 21-May-2015: I temporarily removed the source code to make major changes to the program. Regards, Joe In a previous Experts Exchange article, How To Rename-Move a Batch of PDF Files Based on Contents of the Files (http://www.experts-exchan…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
###### Suggested Courses
Course of the Month11 days, 2 hours left to enroll