Reputation:
I am trying to get a sheet to populate data in a new tab, I need three columns type, service and date/month. However, the getMonth statement keeps throwing an error and I'm unsure why?
var service = inputSheet.getRange('O' + lastRow).getValue();
var date = inputSheet.getRange('L' + lastRow).getValue();
var month = date.getMonth();
I expected this to return the date held in variable date as the month it was entered.
Upvotes: 0
Views: 82
Reputation: 1770
You have to explicitly create a JavaScript / Google Apps Script Date object using the value returned by getValue():
var date = new Date(inputSheet.getRange('L' + lastRow).getValue());
var month = date.getMonth();
Note: getMonth() returns a value 0 - 11 not 1 - 12.
Upvotes: 1