Quantcast
Channel: Adobe Community : Popular Discussions - JavaScript
Viewing all articles
Browse latest Browse all 12130

Calculations Between Two Time Fields

$
0
0

Hello,

 

I have a form with a Time Field for the start time, and a text field for the user to enter a duration (eg 00:30:00).

 

There is another field for the End Time (which will have a calculation script using the start time and duration fields).

 

The script which has been placed in the End Time Field works except the script is giving a negative result.

 

Eg start time field is 16:03:33  and duration field is 00:30:00  Calculation for End Time Field is showing as -16:-33

 

Can someone please advise how I can revise the script for the End Time Field to show the correct result of 16:33 (without the negative)?


// create string for today's date
var oToday = new Date();
var sToday = util.printd("yyyy/mm/dd ", oToday);

// get value of start time field

var sStart = this.getField("Action Start Time").value;

// create JavaScript date time object for start time
var oStart = util.scand("yyyy/mm/dd HH:MM:ss", sToday + sStart);


// get value of duration

var sEnd = this.getField("Action Time").value;

// create JavaScript date time object for end time
var oEnd = util.scand("yyyy/mm/dd hh:mm", sToday + sEnd);

 

// compute difference in hours from the difference in hours
var DiffHours = (oEnd.valueOf() - oStart.valueOf()) / 1000 / 60 / 60;
event.value = Math.floor(DiffHours)+ ":" + util.printf("%,302.0f", (((DiffHours % 1) * 60).toFixed()));

 

 

Any assistance will be greatly appreciated.


Viewing all articles
Browse latest Browse all 12130

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>