I need to get rid of / set to zero the time in the timestamp. I can do it with the singular cell, but struggle to mimic the same logic for the whole column.
Thanks.
function timestampFormat(){
var SS = SpreadsheetApp.openById('xxx')
var k = new Date(SS.getSheetByName("S1").getRange('a3').getValues());
Logger.log(k);
var formattedDate = new Date(k.setHours(0,0,0,0));
Logger.log(formattedDate);
var rn= SS.getSheetByName("S1").getRange(1,1,10).getValues();
Logger.log(rn);
// var formDates = [];
// for (var i = 0; i < rn.length; i ){
// var formDates[i] =new Date(rn.setHours(0,0,0,0)); }
// Logger.log(formDates);
}
CodePudding user response:
In your situation, how about the following modification? The method of getValues
returns 2 dimensional array. So in this modification, each value is converted using map
.
From:
var rn= SS.getSheetByName("S1").getRange(1,1,10).getValues();
To:
var rn = SS.getSheetByName("S1").getRange(1, 1, 10).getValues();
var res = rn.map(([a]) => [a instanceof Date ? new Date(a.setHours(0, 0, 0, 0)) : a]);
console.log(res)