Context
I want to dynamically change the data format in the respective columns of the below to a proper date format: I used this code but now want to make it dynamic. The original number formats in the date columns are date/time formats from google finance. But I just want the format in dd/mm/yyyy.
This was my original code:
function Dateformats() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Within the values copied spreadsheet, columns that have 'Date' will be the subject of this function
var sheet = spreadsheet.getSheetByName('Values (Live Data copied)')
// var sheet = spreadsheet.getSheetByName("Values (Live Data copied)")
var dataList = sheet.getRangeList(['A:A', 'C:C', 'E:E', 'G:G', 'I:I', 'K:K', 'M:M', 'O:O']);
dataList.setNumberFormat('dd/MM/yyyy');
}
New code for dynamic results
function Dateformats() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Within the values copied spreadsheet, columns that have 'Date' will be the subject of this function
var range = spreadsheet.getRangeByName('Values (Live Data copied)!Date')
if(range !== null){
range.setNumberFormat('dd/MM/yyyy');
}
}
Both work though the latter does not actually show up on the sheet. The date formats still remain unchanged.
Problem
Is anyone aware of a fix for the dynamic reformating of columns that have 'Dates' in them?
