Search code examples
javascriptgoogle-apps-scriptgoogle-sheetshtml-email

APPS SCRIPT DATE FORMAT ISSUE


I'm trying to send a table from google sheets to gmail using apps script, i have multiple dates and i want to send in this format "dd-mm-yy", but the problem is that i need to use utilites.formatdate which coverts the cell into string, so when i try to send the email it diplays that the parameters dont match the method, i think this is because in some cells date could be not fullfilled, so theres nothing written in the cell, because of this error i cant send the email, if i write dates in the cells it works but there are cases when they are not fullfilled as i said, how can i solved this problem and send the email no matter if all the dates are filled or not?

var fecha = registro.getRange("c16").getValue();
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");

This is the way i tried to change the format, and if there is someting written works but

var fecha2 = registro.getRange("e16").getValue();
var fecha2F = Utilities.formatDate(fecha2, "GMT","dd-MM-YY");

In the second there is nothing so it displays the error

Hope you can help me guys

I'm learning so all kind of advices you give to me are welcome


Solution

  • Try this:

    var fecha = new Date(registro.getRange("c16").getValue());
    var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");