title: Google app script export CSV from google spreadsheet date format
body: <p>I am using a Google app script to export from spreadsheet to CSV.
  In my spreadsheet, I have columns with date format: DD/MM/YYYY
  But in the CSV the date becomes like that: </p>
  
  <pre><code>Fri Mar 20 2020 00:00:00 GMT+0300 (heure normale d’Afrique de l’Est)
  </code></pre>
  
  <p>Instead of DD/MM/YYYY</p>
  
  <p>Any help will save my day :-)</p>
  
  <p>In my code I have a line regarding the date, but it doesn't work or transform date data to string? : function isValidDate(date)</p>
  
  <p>The code I use : </p>
  
  <pre><code>function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var csvMenuEntries = [{
  name: "export as csv file",
  functionName: "saveAsCSV"
  }];
  ss.addMenu("CSV Export", csvMenuEntries);
  var a1 = ss.getSheetByName("Name").getRange("A1").getValue();
  var name = "MyCompanyName_"+a1;
  ss.rename(name);  
  };
  
  function saveAsCSV() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ssname = ss.getName();
  var sheet = ss.getActiveSheet(); 
  var sheetname = sheet.getSheetName();
  var folder = DriveApp.getFileById(ss.getId()).getParents().next();
  var fileName = ssname + ".csv";
  var csvFile = so_4225484202(fileName);
  folder.createFile(fileName, csvFile);
  
  }
  
  
  function isValidDate(date) {
  return date &amp;&amp; Object.prototype.toString.call(date) === "[object 
   Date]" &amp;&amp; !isNaN(date);
  }
  function so_4225484202(filename) {
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var paramsheet = ss.getSheetByName("Parameters");
  
  var linearray = [];
  var rowdata = [];
  var csv = "";
  var fieldvalue = "";
  
  var param = paramsheet.getRange(2, 2, 2);
  var paramValues = param.getValues();
  var fieldDelimiter = paramValues[0][0];
  var textDelimiter = paramValues[1][0];
  var rangeData = sheet.getDataRange();
  var lastColumn = rangeData.getLastColumn();
  var lastRow = rangeData.getLastRow();
  var rangeValues = rangeData.getValues();
  
  for (i = 0; i &lt; lastRow; i++) {
  for (j = 0; j &lt; lastColumn; j++) {
  
      var value = rangeValues[i][j];
      var theType = typeof value;
  
      if (theType === "object") {
          var testdate = isValidDate(value);
          //Logger.log("if typeof is object: testdate: 
  "+testdate);//DEBUG
          var testtype = typeof testdate;
          if (testtype === "boolean") {
              // variable is a boolean
              //Logger.log("Its a date");//DEBUG
              theType = "date";
          } else {
              //Logger.log("Its not a date");//DEBUG
          }
      }
      if (theType === "string") {
          value = textDelimiter + value + textDelimiter;
      }
  
      rowdata.push([value]);
  };
  
  //Logger.log("DEBUG: rowdata: "+rowdata);//DEBUG
  csv += rowdata.join(fieldDelimiter) + "\n";
  var rowdata = [];
  
  };
  
  return csv;
  
   }
  </code></pre>