I am trying to write a custom function that takes two cell ranges (Start time and Stop time) as input and then outputs the total hours. If the cells are formatted as normal numbers (i.e. 9:00pm is represented as 0.875) the function works fine. If I format the cells as time the cell value the formula is in says “#NUM!” and the tooltip is “error: Overflow”. Is there a way to read the raw cell data without the formatting so that my formula will work?
Formula code
function getHoursTest(startRange, stopRange) {
var hours = 0; // define "hours" with start value of 0
var i = startRange.length - 1; // define "i" and assign the position of the last array element
while(i>=0){
hours = hours + ((stopRange[i] - startRange[i])*24);
i--
}
return hours;
}
When a cell is formatted as a date or time value then it’s value is passed to Apps Script as a JavaScript Date object. You can determine if the value is a date by using code like: