3 Replies Latest reply on Jan 13, 2015 5:44 AM by Ladybird121

# What custom calculation script would i use for: "Finish Time" - "Start Time" = time - "Break" = "Hours Worked"

Help! I have looked all over and typed this question is multiple ways to see what answers are out there and I haven't found an answer that works! I have "start time" and "finish time" in HH:mm and "Hours Worked" in number format. I have a script that can calculate the difference for "finish time " and " start time" but I need to factor in a break into the equation. I have no experience with script stuff so please dumb it down for me. Thanks

• ###### 1. Re: What custom calculation script would i use for: "Finish Time" - "Start Time" = time - "Break" = "Hours Worked"

Since you already have a script that can subtract one time value from

another the easiest way is probably to create a hidden field that will

contain the result of Finish Time-Start Time and then subtract the Break

time from that field and display the result of that calculation in the

Hours Worked field.

• ###### 2. Re: What custom calculation script would i use for: "Finish Time" - "Start Time" = time - "Break" = "Hours Worked"

A lot would depend upon the code you are using. Can you post a sample?

• ###### 3. Re: What custom calculation script would i use for: "Finish Time" - "Start Time" = time - "Break" = "Hours Worked"

Thank you Gilad D, that worked making a hidden field and just creating the subtraction for the break with that field!   But for future reference if anyone else comes across this question, this is what I used for the time without subtracting the break.

// Get first field value

var v1 = getField("Finish Time 1").value;

//Split field value

var time1 = v1.split(":");

// Get second field value

var v2 = getField("Start Time 1").value;

//Split field value

var time2 = v2.split(":");

var min1 = time1[0]*60 + time1[1]*1 //

var min2 = time2[0]*60 + time2[1]*1 ;

event.value = ((min1 - min2) / 60) ;

If anyone know how to add a break into this script, have at it! But creating a hidden field with the answer of the above script and then creating another box that takes that number minus a break worked good.