Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid formatDate error in Google Apps Script

ive got a function to storage in an array and loop data from a document. Inside this one, there are cells with dates in format dd/mm/yyyy...but when I send it by email, appears like Wed Jan 01 2014 00:00:00 GMT-0300 (ART)

I used inside this function, a formatDate method but through me an error Cannot find method formatDate(string,string,string). How I can get the right formated 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;

}
like image 326
user3911545 Avatar asked Oct 20 '14 13:10

user3911545


1 Answers

You need to convert the string to date first before calling the formatDate() method.

temp = new Date(usersExpDate[n]);
temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd");
like image 58
Amit Agarwal Avatar answered Sep 17 '22 23:09

Amit Agarwal