Avoid the formatDate error in Google Apps Script

ive received an array storage function and loop data from a document. Inside this there are cells with dates in dd / mm / yyyy format ... but when I email it it appears as Wed 01.01.2014 00:00:00 GMT-0300 (ART)

I used the formatDate method inside this function, but through me there was an error Unable to find the formatDate method (string, string, string). How can I get the correct formatting date?

function getUsersExpDate(usersExpDate) {

  var expDateArray = [];

  var temp = usersExpDate[0];

  for(var n=0; n < usersExpDate.length; n++){

    expDateArray.push( usersExpDate[n] );    
    temp = usersExpDate[n];
    temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd");

  }

  return expDateArray;

}

      

+3


source to share


1 answer


Before calling the formatDate () method, you need to convert the string to date first.



temp = new Date(usersExpDate[n]);
temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd");

      

+4


source







All Articles