How do I add HHMM from two fields and display hour and tenths of hours in a different field?

New Here ,
Jun 17, 2022 Jun 17, 2022

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.

TOPICS
How to , JavaScript

Views

67

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Jun 17, 2022 Jun 17, 2022

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
...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 17, 2022 Jun 17, 2022

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;
}

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
community guidelines
New Here ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

Thank you so very much!  Works Great!!

 

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
community guidelines
New Here ,
Jun 17, 2022 Jun 17, 2022

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

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
community guidelines
Adobe Community Professional ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

It's possible, but will require a more complex script to round the file in this specific way.

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
community guidelines
Enthusiast ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

LATEST

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;
}

@+

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
community guidelines