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?
JavaScript
x
18
18
1
function getUsersExpDate(usersExpDate) {
2
3
var expDateArray = [];
4
5
var temp = usersExpDate[0];
6
7
for(var n=0; n < usersExpDate.length; n++){
8
9
expDateArray.push( usersExpDate[n] );
10
temp = usersExpDate[n];
11
temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd");
12
13
}
14
15
return expDateArray;
16
17
}
18
Advertisement
Answer
You need to convert the string to date first before calling the formatDate() method.
JavaScript
1
3
1
temp = new Date(usersExpDate[n]);
2
temp = Utilities.formatDate(temp, "GMT", "yyyy-MM-dd");
3