I like to find the beginning of the next month. The beginning on the current month (1st of March) is stored in a Google spreadsheet at B1" but my code returns me 29th of March if I add another month.
The cell B1 holds the value 01.03.2021
.
Screenshot of the sheet with cell B1
function date_next_recort(){
ss = SpreadsheetApp.getActiveSpreadsheet();
sheet = ss.getActiveSheet();
var timezone = ss.getSpreadsheetTimeZone();
var date = new Date(sheet.getRange("B1").getValue());
var record_next = new Date(date);
var month = record_next.getMonth();
record_next.setMonth(month + 1);
Logger.log("ScriptTimeZone: " + Session.getScriptTimeZone());
Logger.log("SheetTimeZone: " + ss.getSpreadsheetTimeZone());
Logger.log('record_start: ' + Utilities.formatDate(date, timezone, 'MMMM dd, yyyy'));
Logger.log('record_next: ' + Utilities.formatDate(record_next, timezone, 'MMMM dd, yyyy'));
return record_next;
}
output:
2:00:49 PM Info ScriptTimeZone: America/New_York
2:00:49 PM Info SheetTimeZone: Europe/Vienna
2:00:49 PM Info record_start: March 01, 2021
2:00:49 PM Info record_next: March 29, 2021