I'm working on a bounded to spreadsheet script for a client, the spreadsheet is owned by them. Among other many things the script should insert today's date into a Google Sheets spreadsheet cell. The problem is that the inserted date is wrong and always the same.
I made a copy of the spreadsheet to try to debug my code / find out what setting is wrong but I'm unable to reproduce the problem, like looking at and playing with the spreadsheet and script project timezone settings.
This is the "minimum" code to insert today's date
function customToday(){
var now = new Date();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheets()[0];
var range = sheet.getRange('A1');
range.setValue(now.getFullYear(),now.getMonth(),now.getDay())
}
Replacing now.getDay()
by other value doesn't change the result.
I finally look to the original spreadsheet settings. The regional setting was blank and the timezone setting was Pacific Time rather the default timezone of the spreadsheet owner.
It looks to me that somehow the regional and timezone settings were corrupted. Changing the regional settings to the client default country and timezone fixed the problem.