Essentially I would like to have a YYYY-MM-DD format inserted into a cell on a new spreadsheet when it is created as plain text. The trouble is that when the inserted value is inserted into the new sheet it appears as DD/MM/YYYY which is unreadable by the other program that is running in the background.
Here is the following code:
function dateTest()
{
var template = SpreadsheetApp.openById('ABC------1234')
var test = template.getSheetByName('TEST');
var database = SpreadsheetApp.getActive().getSheetByName('DASHBOARD');
//start & endDates are in YYYY-MM-DD format in these cells
var startDate = database.getRange('A10').getValue();
var endDate = database.getRange('A11').getValue();
//The results come up as DD/MM/YYYY when they are set into TEST
//Formatted to YYYY-MM-DD has already been done
test.getRange('D1').setValue(startDate);
test.getRange('D2').setValue(endDate);
}
If necessary, the date could be split into YYYY + '-' + 'MM' + '-' + 'DD' and then inserted as plain text, however I am clueless as to how to perform this feat. Any advise would be very much appreciated.
Try this workaround: in the sheet manually set a cell format to "Plain Text" that is not involved in the operation. Let's call this cell J1. Now before calling:
Do something like:
This should let you have clear text format on destination cells.
It can be cleaned up but here are the basics.
In Google Spreadsheets, a leading apostrophe means ignore formatting. Thus, this works:
Alternatively, the text can be quotes and set as a "formula":
(Make sure the string includes double quotes not single quotes - Apps Script is JavaScript and therefore supports either, but spreadsheet formulas don't understand single quotes the same way.)
This will reformat the date and set it as string: