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
  • Learn & ask questions
Solved

Adobe LiveCycle how to calculate time difference

Posted on 2012-04-11
4
2,668 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adobe Flash player - Microsoft Edge 9 175
Acrobat Printing Issues 5 82
VBA to convert all word docs to PDF with Acrobat Pro 2 64
PDF slideshow on a dynamic folder 12 86
This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
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…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

791 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