I'm working on a timesheet which requires that a user's time entry be converted to hours rounded off to the nearest ".25." I have two problems with the script below.
1. If a user enters their time, say 9:03am to 5:00pm, it comes back with "7.10" hours instead of "8.00."
2. If a user enters time that crosses over the date, say 8:00pm to 4:00am, it comes back with "-16.00" instead of "8.00."
var oStart = util.scand("yyyy/mm/dd hh:mm", util.printd("yyyy/mm/dd ", new Date()) + this.getField("TimeIn1").value);
var oEnd = util.scand("yyyy/mm/dd hh:mm", util.printd("yyyy/mm/dd ", new Date()) + this.getField("TimeOut1").value);
var DiffHours = (oEnd.valueOf() - oStart.valueOf()) / 1000 / 60 / 60;
event.value = Math.floor(DiffHours)+ "." + util.printf("%,302.0f",((DiffHours % 1) * 4).toFixed()) * 25
Any help would be much appreciated.
> 1. If a user enters their time, say 9:03am to 5:00pm, it comes back with "7.10" hours instead of "8.00."Use the "Math.ceil()" method to round up to the next higher whole number.
> 2. If a user enters time that crosses over the date, say 8:00pm to 4:00am, it comes back with "-16.00" instead of "8.00."You will need to include a date field for the start and end times and not force the current date into the date time object for the start and end times. Or add some code to test if the start time is later than the end time and "assume" the start date was the day before the end date. "new Date()" returns the current date.
George Kaiser