Goal: I'm using the following code to simply test if I am able to extract the correct date and the number of days.
function myFunction() {
const spreadSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Purchases (Beta)');
const getDate = new Date(spreadSheet.getRange('B4').getValue());
const getDays = (new Date(getDate.getFullYear(), getDate.getMonth() + 1, 0)).getDate();
Logger.log(getDate);
Logger.log(getDays);
}
Intention of the code: The getDate is supposed to get the date from cell B4, which it includes a date formatted value as "2020-11-01." As to getDays, it's supposed to get the number of days based on the set value of cell B4.
Issue: When I tried to log out the result for getDate, it shows as: Sat Oct 31 20:00:00 GMT-04:00 2020. Which I don't understand because the value in B4 is 2020-11-01.
Question: I want to understand why this happens and want to know how I can out put the correct date based on what is in the cell of B4.
Can someone help?