Copy link to clipboard
Copied
I am trying to add two different times; flight start and end time that are in hhmm. And display the answer in tenths of an hour. 0900 take off, 1005 landing. Equals 1.1 flight time. I do not have any javascript experience!
In the attached form - is the FROM and the second TO block I would like the add and display the total flight time in the FLT HRS block.
You can do it using this code:
var time1 = this.getField("TAKE OFF TIME FLT 1").valueAsString;
var time2 = this.getField("SHUTDOWN TIME FLT 1").valueAsString;
if (time1==" " || time2==" ") event.value = "";
else {
var hours1 = time1.substring(0,2);
var hours2 = time2.substring(0,2);
var minutes1 = time1.substring(2,4);
var minutes2 = time2.substring(2,4);
var totalTimeInMins = (hours2-hours1)*60 + (minutes2-minutes1);
var totalTime = (totalTimeInMins/60).toFixed(1)
event.value = totalTi
...
Copy link to clipboard
Copied
You can do it using this code:
var time1 = this.getField("TAKE OFF TIME FLT 1").valueAsString;
var time2 = this.getField("SHUTDOWN TIME FLT 1").valueAsString;
if (time1==" " || time2==" ") event.value = "";
else {
var hours1 = time1.substring(0,2);
var hours2 = time2.substring(0,2);
var minutes1 = time1.substring(2,4);
var minutes2 = time2.substring(2,4);
var totalTimeInMins = (hours2-hours1)*60 + (minutes2-minutes1);
var totalTime = (totalTimeInMins/60).toFixed(1)
event.value = totalTime;
}
Copy link to clipboard
Copied
Thank you so very much! Works Great!!
Copy link to clipboard
Copied
One more request. Is there a way to change where the calculation to the next tenth happens? Forexample: 1 hour or 1.0 should from 56 mins to 60 min. 1.1 should be from 61 min to 66 min. So ever six mins should cause the next .1 (this is how we count time in Army aviation)
min
1-6 = .1
7-12= .2
13-18 = .3
19-24= .4
25-30= .5
31-35= .6
...etc
Copy link to clipboard
Copied
It's possible, but will require a more complex script to round the file in this specific way.
Copy link to clipboard
Copied
Hi,
Here is a script from the one of try67 which should match your expectation:
var time1 = this.getField("TAKE OFF TIME FLT 1").valueAsString;
var time2 = this.getField("SHUTDOWN TIME FLT 1").valueAsString;
if (time1==" " || time2==" ") event.value = "";
else {
var hours1 = time1.substring(0,2);
var hours2 = time2.substring(0,2);
var minutes1 = time1.substring(2,4);
var minutes2 = time2.substring(2,4);
var totalTimeInMins = (hours2-hours1)*60 + (minutes2-minutes1);
// BB
var rest=(totalTimeInMins/60)%1;
if (rest<=.1) rest=.1;
else if (rest<=.2) rest=.2;
else if (rest<=.3) rest=.3;
else if (rest<=.4) rest=.4;
else if (rest<=.5) rest=.5;
else if (rest<=.6) rest=.6;
else if (rest<=.7) rest=.7;
else if (rest<=.8) rest=.8;
else if (rest<=.9) rest=.9;
else rest=1.0;
var totalTime = (Math.floor(totalTimeInMins/60)+rest).toFixed(1);
//
event.value = totalTime;
}
@+