I Am trying to create a script that appends a new line to a draft with various information for recording expenses. I am getting hung up on the first item the date. Below I have tried to combine a couple of examples to select and format a date.
The error I get is:
Script Error: TypeError: undefined is not an object (evaluating ‘now.getFullYear’)
Line number: 6, Column 17
I am thinking that it has to do with my passing myDate to the function. Can anyone point me in the right direction?
function getDateTime(now) {
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
if(month.toString().length == 1) {
var month = ‘0’+month;
}
if(day.toString().length == 1) {
var day = ‘0’+day;
}
var dateTime = year+’-’+month+’-’+day;
return dateTime;
}
var p = Prompt.create();
p.addDatePicker(“myDate”, “Date Field”, new Date(), {
“mode”: “date”});
// p.addSelect(“myCategory”, “Expense Category”, [“Airfare”, “Lodging”, "Meals "], [], false);
p.addButton(“Ok”);
if (p.show()) {
editor.setSelectedText(getDateTime(p.myDate));
var selRange = editor.getSelectedRange();
editor.setSelectedRange(selRange[0]+selRange[1],0);
};