On my Google Sheets macro, I want it to get the first date of the previous month, and insert it into a cell.
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() - 1;
var lastMonthStart = new Date(year, month, 1);
Logger.log(lastMonthStart)
dataDashboard.getRange(1, 1).setValue(lastMonthStart)
When I run this, the correct date is recorded in the logger:
[19-10-18 10:51:38:454 PDT] Sun Sep 01 00:00:00 GMT+01:00 2019
but in the sheet, it puts 31/08/2019 16:00:00
I'm guessing this is something to do with timezones, and maybe wherever the macro is running has a different timezone to the sheet and is trying to be helpful and correct it. How can I stop this?