title: Google Scripts Javascript Date Error
body: <p>I wrote texting software that, when a number receives a text, writes to a google spreadsheet the date and other information. The date is the main subject of this question. The texting information is written to a google spreadsheet. I have another spreadsheet that is written to when the texting number receives a certain input. When the month of the dates change, I want the new spreadsheet to create a break in the month recording, and create a heading for a new month. In order to write to the new spreadsheet and not overwrite the old entries, I am using this function:</p>
  
  <pre><code>var getFirstEmptyRowWholeRowInPaymentSheet = function() {
    var sheet = SpreadsheetApp.openById("Spreadsheet ID");
    var range = sheet.getDataRange();
    var values = range.getValues();
    var row = 0;
    for (var row=0; row&lt;values.length; row++) {
      if (!values[row].join("")) break;
    }
    return (row+1);
  }
  </code></pre>
  
  <p>As I said before, I want to compare the date that the text was received on with the old date. Here is the log statements I was using to try to figure out the problem:</p>
  
  <pre><code>var finalRow = getFirstEmptyWholeRowInPaymentSheet();
      var dayHolder = splitDate[1];
               var amountPaid = messageBody.split(" ")[2];
              Logger.log("Final Row: " + finalRow);
              Logger.log("Final Row - 1: " + (finalRow-1));
              Logger.log("Recieved Date: " + e.values[0]);
              Logger.log("Previous Date: " + paymentData.getCell((finalRow-1),1).getValues());
              Logger.log("Previous previous date: " + paymentData.getCell((finalRow - 2),1).getValues());
              Logger.log("Previous previous date: " + paymentData.getCell((finalRow - 3),1).getValues());
              Logger.log("Previous previous date: " + paymentData.getCell((finalRow - 4),1).getValues());
              Logger.log("Previous previous date: " + paymentData.getCell((finalRow - 5),1).getValues());
  </code></pre>
  
  <p>This is what the log looks like:</p>
  
  <pre><code>1: Final Row: 10
  2: Final Row - 1: 9
  3: Received Date: 1/6/2017 10:32:18
  4: Previous Date: Sun Jan 01 2017 00:00:00 GMT-0800 (PST)
  5: Previous previous date: undefined
  6: Previous previous date: undefined
  7: Previous previous date: undefined
  8: Previous previous date: undefined
  </code></pre>
  
  <p>This is not correct, the previous date should be 1/6/2017 10:17:47. Can someone please help me understand why google scripts is defaulting to Sun Jan 01 2017 00:00:00 GMT-0800 (PST)?</p>