I'm new to google apps script, and I'm having trouble parsing date strings from a UiApp form. In this instance, I'm writing a script to allow the user to filter a timestamped spreadsheet within a specified date range.
My problem is that the code below returns an invalid date object when passed a date string (from a text box named dateFromField
) in the conventional javascript format YYYY,M,D
(i.e. 2012,1,2
for Feb 2, 2012):
function dateFilter(e) {
var fromDate = new Date(e.parameter.dateFromField);
}
I've checked that the e.parameter.dateFromField
correctly returns the given string (Logger.log(e.parameter.dateFromField);
returns 2012,1,2
), and that its type is string (rather than object).
However, if I type the date string into the function directly, i.e.:
function dateFilter(e) {
var fromDate = new Date(2012,1,2);
}
I get valid a date object. I don't understand the difference between these two examples - as far as I can tell they are equivalent; in both instances the string 2012,1,2
is being passed to the new Date
function. I'm obviously missing something simple - can anyone tell me what?