Copy link to clipboard
Copied
Hi all,
Got a pdf with fillable fields, TIME OUT & TIME IN. Both are entered as HH:MM. No seconds, no date. 24hr clock. I want to find time difference between them also dispalyed in HH:MM. ie time in 12:00, time out 14:30....elapsed time...02:30. I cant get a head of this and its bugging me. Can anyone help?
Copy link to clipboard
Copied
This issue was discussed many (many) times on these forums, including full codes to do it. Have you tried searching around a bit?
Copy link to clipboard
Copied
Sort of, but some are with YYYY, or HHMMSS, I'm a basic IT person. Can you point me in the direction ?
Copy link to clipboard
Copied
Just adjust the time format to the one you use, then... It doesn't have to contain the date part.
Copy link to clipboard
Copied
Alright, i'll have a search around
Copy link to clipboard
Copied
would this work?
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
function diff(start, end) {
start = start.split(":");
end = end.split(":");
var startDate = new Date(0, 0, 0, start[0], start[1], 0);
var endDate = new Date(0, 0, 0, end[0], end[1], 0);
var diff = endDate.getTime() - startDate.getTime();
var hours = Math.floor(diff / 1000 / 60 / 60);
diff -= hours * 1000 * 60 * 60;
var minutes = Math.floor(diff / 1000 / 60);
return (hours < 9 ? "0" : "") + hours + ":" + (minutes < 9 ? "0" : "") + minutes;
}
document.getElementById("diff").value = diff(start, end);
Copy link to clipboard
Copied
The basic code seems fine, although I didn't test it, but it was written for an HTML page, not a PDF file.
Change all instances of document.getElementById(...) to this.getField(...) .
Copy link to clipboard
Copied
so this?
var start = this.getField("TimeOut") ..value;
var end = this.getField("TimeIN") ..value;
function diff(start, end) {
start = start.split(":");
end = end.split(":");
var startDate = new Date(0, 0, 0, start[0], start[1], 0);
var endDate = new Date(0, 0, 0, end[0], end[1], 0);
var diff = endDate.getTime() - startDate.getTime();
var hours = Math.floor(diff / 1000 / 60 / 60);
diff -= hours * 1000 * 60 * 60;
var minutes = Math.floor(diff / 1000 / 60);
return (hours < 9 ? "0" : "") + hours + ":" + (minutes < 9 ? "0" : "") + minutes;
}
this.getField("diff") ..value = diff(start, end);
Copy link to clipboard
Copied
No, it should be followed by only one period, not two, and remove the space before the period.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That seems about right, yes.
Copy link to clipboard
Copied
Hi sir
Yep that works perfect. Working great. see here.
var start = this.getField("Take Off Z1").value; var end = this.getField("Landing Z1").value; function diff(start, end) { start = start.split(":"); end = end.split(":"); var startDate = new Date(0, 0, 0, start[0], start[1], 0); var endDate = new Date(0, 0, 0, end[0], end[1], 0); var diff = endDate.getTime() - startDate.getTime(); var hours = Math.floor(diff / 1000 / 60 / 60); diff -= hours * 1000 * 60 * 60; var minutes = Math.floor(diff / 1000 / 60); return (hours < 9 ? "0" : "") + hours + ":" + (minutes < 9 ? "0" : "") + minutes; } this.getField("Flight Time1").value = diff(start, end);
however, in my fields I have Nan:Nan. How to get rid of that in my code? Also, I have formula in thr 'Fuel Used' whicy us dep fuel - arr fuel...that works fine. In that field, I can''t edit/type anything in (as expected). However in the Flight Time field (nan:nan), it will let me type in text over the top? Why isnt this cell 'blocked' off too?
If I put all times as 'none' formatting, I get NAN. If I put all to TIME HH:MM, then when the fields are empty, it says "
The value entered does not match the format of the field [ Flight Time1 ]"
What am I doing wrong here, and how to remove the nan:nan from my code?
Thanks. pic below.
Also I