title: Return empty date field when sending it by email (Google Spreadsheet)
body: <p>I got the below code running ok, but when a date field is empty, I get the email with related field containing 01/01/1970. How can I insert a condition that prevents these date fields from getting filled in?</p>
  
  <pre><code>function sendEmailbyTransporter() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Status de Embarque Integrado");
  
    // Get your table data
    var startRow = 27;  // First row of data to process
    var numRows = sheet.getLastRow(); // Number of rows to process
    var dataRange = sheet.getRange(startRow, 1, numRows, 12); // Fetch the range including the Minimums
    var data = dataRange.getValues(); // Fetch values for each row in the Range.
  
    // Loop through the data to build your table
    var message = "&lt;html&gt;&lt;body&gt;&lt;table style=\"text-align:center\"&gt;&lt;tr&gt;&lt;th&gt;NF&lt;/th&gt;&lt;th&gt;CT-E&lt;/th&gt;&lt;th&gt;Cliente&lt;/th&gt;&lt;th&gt;Cidade&lt;/th&gt;&lt;th&gt;UF&lt;/th&gt;&lt;th&gt; Previsão de Entrega&lt;/th&gt;&lt;th&gt;Ocorrência&lt;/th&gt;&lt;th&gt;Detalhe da Ocorr.&lt;/th&gt;&lt;th&gt;Data da Entrega&lt;/th&gt;";
    var sendEmail = false; // If there is content to send, will be set to true
    for (var i = 0; i &lt; data.length; ++i) {
      var rowData = data[i];
      var NF = rowData[0];
      var Email = sheet.getRange("I24:l24").getValue();
      if (NF != "") { //Checks for blank Code. If blank, then skip and don't add to the table.
        var CTE = rowData[1];
        var CTEAsDate = Utilities.formatDate(CTE, "GMT" , "dd/MM/yyyy" );
        var Cliente = rowData[4];
        var Cidade = rowData[5];
        var UF = rowData[6];
        var PrevEntrega = new Date(rowData[7]);
        var PrevEntregaAsDate = Utilities.formatDate(PrevEntrega, "GMT" , "dd/MM/yyyy" );
        var Ocorr1 = rowData[10];
        var Ocorr2 = rowData[11];
        var Entrega = new Date(rowData[12]);
        var EntregaAsDate = Utilities.formatDate(Entrega, "GMT" , "dd/MM/yyyy" );
  
          message += "&lt;tr&gt;&lt;td&gt;"+NF+"&lt;/td&gt;&lt;td style=\"text-align:left\"&gt;"+CTE+"&lt;/td&gt;&lt;td&gt;"+Cliente+"&lt;/td&gt;&lt;td&gt;"+Cidade+"&lt;/td&gt;&lt;td&gt;"+UF + "&lt;/td&gt;&lt;td&gt;"+PrevEntregaAsDate+"&lt;/td&gt;&lt;td&gt;"+Ocorr1 + "&lt;/td&gt;&lt;td&gt;"+Ocorr2 + "&lt;/td&gt;&lt;td&gt;"+EntregaAsDate + "&lt;/td&gt;&lt;/tr&gt;";
          sendEmail = true; //There is content to send
      }
    }
    message += "&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;";
      if (sendEmail) {
        var subject = "Status de Embarque da NF " + NF + "!";
        MailApp.sendEmail({
          name: 'XXXl',
          to: Email, 
          subject: subject, 
          htmlBody: message
        });
     }
  }
  </code></pre>