Solved

Adobe LiveCycle how to calculate time difference

Posted on 2012-04-11
4
2,574 Views
Last Modified: 2014-05-14
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
Comment
Question by:NCSO
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 500 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

by:puppydogbuddy
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

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

Expert Comment

by:Amy An
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now