Skip to main content
Participant
August 16, 2017
Question

Calculate the differerence in time for over 24 hour period using military time.

  • August 16, 2017
  • 0 replies
  • 273 views

I would like to be able to cross the 23:59 time span. Using Acrobat Pro XI.

Result as decimal: Field: 'Time5Dec.5'

event.value = '';

// get the start time

var sStart = this.getField('TimeIn.5').value;

// get the end time

var sEnd = this.getField('TimeOut.5').value;

// complete script only if we have data

if(sStart != '' & sEnd != '') {

// convert sStart string to seconds

var fStart = Time2Num('hh:mm', sStart);

// convert sEnd string to seconds

var fEnd = Time2Num('hh:mm', sEnd);

// compute difference in seconds

var fDiff = fEnd - fStart;

// convert to rounded minutes

fDiff = Math.round(fDiff / 60);

// report decimal hours

event.value = fDiff / 60;

}

Result as HH:MM Field: 'TimeHHMM.5'

event.value = '';

// get the start time

var sStart = this.getField('TimeIn.5').value;

// get the end time

var sEnd = this.getField('TimeOut.5').value;

// complete script if we have data

if(sStart != '' & sEnd != '') {

// convert sStart string to seconds

var fStart = Time2Num('hh:mm', sStart);

// convert sEnd string to seconds

var fEnd = Time2Num('hh:mm', sEnd);

// convert sEnd string to seconds

var fEnd = Time2Num('hh:mm', sEnd);

// compute difference in seconds

var fDiff = fEnd - fStart;

// convert to rounded minutes

fDiff = Math.round(fDiff / 60);

// get hours from fDiff

fHours = Math.floor(fDiff / 60);

// get minutes less than hour from fDiff

fMins = ((fDiff / 60) - fHours ) * 60;

// format fMins with leading zero

sMins = util.printf("%,302.0f", fMins);

// build display string

event.value = fHours + ':' + sMins;

}

Message was edited by: Kevin Lyons

This topic has been closed for replies.