I am trying to subtract days in google apps script following the solution from this post: Trying to subtract 5 days from a defined date - Google App Script
However, the year does not deduct by 1 if we minus one day from the first day of the year. Below are my code:
var StartDate = new Date(ResponceDetails[C3StartDate]);
var StartYear = StartDate.getYear();
var StartMonth = StartDate.getMonth();
var StartDay = StartDate.getDate();
var tempEndDate = new Date(StartYear+1, StartMonth, StartDay);
Logger.log(StartDate);
Logger.log(tempEndDate);
var EndDate = Utilities.formatDate(new Date(tempEndDate.getTime()-(24*3600*1000)),"GMT+8","MM/dd/YYYY");
Logger.log(EndDate);
The purpose of this code is to calculate the due date of user after 1 year (including start day). So it has to be plus one year and minus by 1 day. Does the code above ok or anyone having a similar problem?
Thank you