Question

I'm writing a Google Apps Script that is supposed to send warning emails when the date of a certain event approaches. I have all the events set up in a Google Spreadsheet, and each event has a start and end date associated with it.

I'm running into problems when trying to parse the date from the cells in the spreadsheet. When I obtain the value of the date in the cell, it doesn't actually return a Date object, so I can't create a Date straight up from the values obtained from the cell. I can, however, convert it to a string and then split the string on space tokens to obtain the year, month, and day. Now this is where the problem occurs; it won't let me perform .parseInt() on the resulting variable, and I can't figure out why. So far, the code for the function I'm making to convert the date obtained from the spreadsheet looks like this:

function convertToDateObject(date)
{
  var months = 
      {
        'Jan' : '01',
        'Feb' : '02',
        'Mar' : '03',
        'Apr' : '04',
        'May' : '05',
        'Jun' : '06',
        'Jul' : '07',
        'Aug' : '08',
        'Sep' : '09',
        'Oct' : '10',
        'Nov' : '11',
        'Dec' : '12'
      };

  var dateArray = date.toString().split(" ");
  var month = dateArray[1].parseInt(); // This is actually in the form of name (e.g. Jan, Feb, etc.), but I know how to change this already 
  var day = dateArray[2].parseInt();
  var year = dateArray[3].parseInt();
}

That's all I have so far, because when I try to compile, I get an error stating: "Cannot find function parseInt in object ..."

If I do typeof month, day, or year, it returns string. Can anyone help me?

Was it helpful?

Solution

String doesn't have any parseInt method. The parseInt is a global function http://www.w3schools.com/jsref/jsref_parseint.asp

  var dateArray = date.toString().split(" ");
  var month = parseInt(dateArray[1], 10); // This is actually in the form of name (e.g. Jan, Feb, etc.), but I know how to change this already 
  var day = parseInt(dateArray[2], 10);
  var year = parseInt(dateArray[3], 10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top