# Time Sheet Calculations

**taylorl42900175**Aug 18, 2015 6:50 AM

I have a time sheet that I have been working on calculations for and I cannot seem to get any of the calculations to work. I am currently working on the form in adobe acrobat which requires me to use javascript which is way out of my element.

Above is an example of the time sheet I am trying to get calculations for. The guys who fill it out need to be able to input the time as regular time and not in military time to make things easier for them. However, there are 3 time sections to fill out and based off that it should give a total number of hours worked but when entering times I receive negative numbers or it doesn't add properly like shown below.

In the picture it shows that the total hours put in =.40 when it should really =12hrs.

So far this is what I have for javascript but that is only for 1 in and out period (time section ex: morning in/out).

function Time2Num(sTime, cFormat) {

// convert a date time string to seconds since the epoch date

var oTime = util.scand(cFormat, sTime); // date time object

var fTime = oTime.valueOf(); // time string to milliseconds

return Math.round(fTime / 1000); // return rounded seconds

}

function TimeDiff(sEnd, sStart) {

// compute difference in time within same day as minutes

var fEnd = 0; // default value if not data

var fStart = 0; // default value if not data

var cDateFormat = "m/d/yyyy "; // date format string

var sNowDate = util.printd(cDateFormat, new Date()); // get today's date as "m/d/yyyy'

var cDateTimeFormat = cDateFormat + "h:MM tt";

// compute difference if we have data

if(sEnd != "" & sStart != "") {

// get end time in minutes

var cDateTimeValue = sNowDate + sEnd; // start date time string

var fEnd = Time2Num(cDateTimeValue, cDateTimeFormat) / 60; // convert to seconds and divide by 60 sec

// get start time in minutes

var cDateTimeValue = sNowDate + sStart; // start date time string

var fStart = Time2Num(cDateTimeValue, cDateTimeFormat) / 60; // convert to seconds and divide by 60 sec

} // end if we have value

return fEnd - fStart; // compute and return the difference in minutes

} // end function

function Mins2HrsMins(fMinutes) {

// convert seconds into formatted string of hours:minutes

var cDisplayFormat = "%01.0f" + ":" + "%02.0f"; // format for returned value

var fHrs = Math.floor(fMinutes / 60); // compute whole hours from the difference

var fMins = fMinutes % 60; // get minutes less than 1 hour form the difference

return util.printf(cDisplayFormat, fHrs, fMins); // format and return computed value

} // end function

var fDiff = TimeDiff(this.getField("Time Out 1").value, this.getField("Time In 1").value)

event.value = Mins2HrsMins(fDiff); // format computed value

Could someone please help me out and write a code for me that will make the hours calculate correctly? I am willing to try anything because at this point I cannot figure out the calculations to save my life! Thanks Much!