简体   繁体   中英

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;

}

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");

@Amit sir - Awesome.;. It worked sirji, I have had the same issue and NO ONE HELPED. I have been learning javascript and it was really TOUGH for me to identify the issue and find a solution. So had been searching for a solution for this issue form past one week and had given up. was such a disappointment. until I found your solution and BINGO. It worked...

For few this issue might be nothing, but I know the trauma I had been through and finding a solution for he issue was really important for me..I hope everyone can understand...Wish to treat you sir ji...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM