Time Sheet Calculations
- April 26, 2023
- 1 reply
- 1618 views
I've created a time sheet for work, however, I can't seem to figure out how to add the morning time with the afternoon time. I've looked through many of the examples and discussions through the forum, but cant seem to find exactly what I'm looking for. I'm just trying to figure out the first row. Please help
Here is my code:
if (((this.getField("MorningR1Out").value.length == 0) || (this.getField("MorningR1In").value.length == 0)) && ((this.getField("AfternoonR1Out").value.length == 0) || (this.getField("AfternoonR1In").value.length == 0)))
{ event.value = " 0 Hours 0 Minutes"; }
else
{ var mortimefinishedR1 = this.getField("MorningR1Out").value;
var morningtimestartedR1 = this.getField("MorningR1In").value;
var afttimefinishedR1 = this.getField("AfternoonR1Out").value;
var afttimestartedR1 = this.getField("AfternoonR1In").value;
var mordatetimefinishedR1 = new Date('1970/01/01' + " " + morntimefinishedR1);
var mordatetimestartedR1 = new Date('1970/01/01' + " " + mortimestartedR1);
var aftdatetimefinishedR1 = new Date('1970/01/01' + " " + afttimefinishedR1);
var aftdatetimestartedR1 = new Date('1970/01/01' + " " + afttimestartedR1);
var mordifflnMilliSecondsR1 = Math.abs(mordatetimefinishedR1 - mordatetimestartedR1)/1000;
var aftdifflnMilliSecondsR1 = Math.abs(aftdatetimefinishedR1 - aftdatetimestartedR1)/1000; // calculate morning hours
var morhoursR1 = Math.floor(mordifflnMilliSecondsR1 / 3600) % 24; mordifflnMilliSecondsR1 -= morhoursR1 *3600;
// calculate afternoon hours
var afthoursR1 = Math.floor(aftdifflnMilliSecondsR1 / 3600) % 24; aftdifflnMilliSecondsR1 -= afthoursR1 *3600;
// calculate morning minutes
var morminutesR1 = Math.floor(mordifflnMilliSecondsR1 / 60) % 60; mordifflnMilliSecondsR1 -= morminutesR1 * 60;
// calculate afternoon minutes
var aftminutesR1 = Math.floor(mordifflnMilliSecondsR1 / 60) % 60; aftdifflnMilliSecondsR1 -= aftminutesR1 * 60;
//morning var
var MorTimeR1 = morhoursR1 + morminutesR1;
//afternoon var
var AftTimeR1 = afthoursR1 + aftminutesR1;
// set field value to the difference
event.value = MorTimeR1 + AftTimeR1; }
