Problems with calculating time differences in Form fields
Form fields are:
Date -(generated by a button action. code= this.getField("Date").value = util.printd("mmm d, yyyy",new Date());
Start -Time Formatted to HH:MM
Finish-Time Formatted to HH:MM
Result -just require a decimal hrs value as a number is fine
I want the result field to display the decimal hours difference between the start and finish time and this difference may cross midnight, but not more than 24hrs difference total. There is a lot of info on this, For example this works
Credit: Thom Parker
var strStart = this.getField("Start").value;
var strEnd = this.getField("Finish").value;
if(strStart.length && strEnd.length)
{
var dateStart = util.scand("dd/mm/yy HH:MM",strStart);
var dateEnd = util.scand("dd/mm/yy HH:MM,",strEnd);
var diff = dateEnd.getTime() - dateStart.getTime();
var onehour = 60 * 60 * 1000;
var oneDay = 24 * 60 * 60 * 1000
var days = Math.floor(diff/oneDay);
event.value = (diff/onehour);
}
else
event.value = "";
BUT I cannot get any of it to work without having to make the time fields formats into dd/mm/yy HH:MM.
I would like to be able to keep the time entries as simple as possible.
It would be a bonus if the Time fields did not require the : to be typed each time as there are a few of them to complete. ie typing the keystrokes 0800 would automatically fill the field as 08:00.
Would hidden fields adding date in millisec to time in millisec help?
Then use variables to subtract these field values and if the result is negative add 24hrs worth of millisec
Then convert to an number of hrs. The result is best as a number value anyway for further calculation
