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

New Here ,
Aug 16, 2017

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

81

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Aug 16, 2017

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

82

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 16, 2017 0

Have something to add?

Join the conversation