Getting and illegal character in a work hrs calculation
I am getting an illegal character error in line 7. I'm trying to determine the number of hours worked between two time, including if the time cross over midnight. Can you review and let me know what the error is?
if ((this.getField("End time").value.length == 0) || (this.getField("Start time").value.length == 0)) {
event.value = " 24.0";
}
else{
var time1 = this.getField(“Text1”).value;
var time2 = this.getField(“Text2”).value;
// convert to date
var datetime1 = new Date(‘1970/01/01 ‘ + time1);
var datetime2 = new Date(‘1970/01/01 ‘ + time2);
var diffInMilliSeconds = Math.abs(datetime1 – datetime2) / 1000;
// calculate hours
var hours = Math.floor(diffInMilliSeconds / 3600) % 24;
diffInMilliSeconds -= hours * 3600;
// calculate minutes
var minutes = Math.floor(diffInMilliSeconds / 60) % 60;
diffInMilliSeconds -= minutes * 60;
// set field value to the difference
event.value =hours + “:” +minutes;
var result;
if (endMin < startMin) {
var minutesPerDay = 24*60;
result = minutesPerDay - startMin; // Minutes till midnight
result += endMin; // Minutes in the next day
} else {
result = endMin - startMin;
}
var minutesElapsed = result % 60;
var hoursElapsed = (result - minutesElapsed) / 60;
alert ( "Elapsed Time : " + hoursElapsed + ":" + (minutesElapsed < 10 ?
'0'+minutesElapsed : minutesElapsed) ) ;
