0
votes

I am trying to pass the value "input1" to the HTML dialog box. It seems simple enough . . . thank you for any help. Code.gs

function doGet() {
      var ss = SpreadsheetApp.openByUrl(url);//Spreadsheet url
      var ws = ss.getSheetByName("Options");
   var tmp = HtmlService.createTemplateFromFile("page");
  tmp.input1 = ws.getRange("A2").getValues();//cell valve is 01-01-2020
   return tmp.evaluate();

}

page.html

<html>
<head>
</head>
<body>
<input  value="<?!= input1;?>" type="text" >
</body>
</html>

It works perfect but and get value from cell date format is “Wed Jan 01 2020 12:30:00 GMT+0530 (India Standard Time)” but I want in different format like “01-01-2020”

2

2 Answers

0
votes

You could format the date using Utilities.formatDate(date, timeZone, format)

And if you don't want to hardcode the timezone, you could use

var timeZone = Session.getScriptTimeZone();
0
votes

Sample:

function doGet() {
   var ss = SpreadsheetApp.openByUrl(url);//Spreadsheet url
   var timeZone = ss.getSpreadsheetTimeZone();
   var ws = ss.getSheetByName("Options");
   var tmp = HtmlService.createTemplateFromFile("page");
   var value = ws.getRange("A2").getValue();//cell valve is 01-01-2020
   tmp.input1 = Utilities.formatDate(value, timeZone,  "dd/MM/yyyy");
   return tmp.evaluate();
}