title: How to compare time in google sheets scripts?
body: <p>In google sheets, I am looping through a range of cells, then splitting the part of the string that contains a time. Example: <code>6:40 AM</code> is derived from <code>TEST:6:40 AM</code> using the line:</p>
  
  <p><code>text.slice(text.indexOf(":") + 1, text.length);</code> </p>
  
  <p>I am then trying to see if this time matches the time of the cell next to the cell that originally called the function.</p>
  
  <pre><code>var sheetTime = timeSheetRange.getCell(1,1).getValue();
  var time = 0;
    for (var i = 1; i &lt;= 30; i++) {
        for (var j = 1; j &lt;= 8; j++) {
            time = getTime(taskRange.getCell(i,j).getValue());
            if (time == sheetTime) {
                return time;
            }
            else {
                return "NO ACTIVITY";
            }
        }
    }
  </code></pre>
  
  <p>The problem is that when putting in the same time values for <code>time</code> and <code>sheeetTime</code>, <code>time</code> does not equal <code>sheetTime</code>.</p>
  
  <p>Returning both <code>time</code> and <code>sheetTime</code> prints out the correct, equal times. I have a feeling that it might have to do with the cell time formatting?
  time is reading from this cell:</p>
  
  <p><a href="https://i.stack.imgur.com/huoAZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/huoAZ.png" alt="time celll"></a></p>
  
  <p>While sheetTime is reading from this cell:</p>
  
  <p><a href="https://i.stack.imgur.com/QB9gl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QB9gl.png" alt="sheetTime cell"></a></p>
  
  <p>SO what's going on here? Is it the formatting that I have to chage or am I approaching this wrong? Thanks.</p>