Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find function getMonth in object 33463

I have created a script to send emails to a specific people with Birthday Reminder. This use to work till day before yesterday. I don't know why am I getting this error that Cannot find function getMonth, Can anyone tell where is the mistake

function emailAlert() {

  // Short circuit if email notice is set to "No". This causes an error and the script stops.
  if (turnOnEmailNotice.toLowerCase() == "no")
  { 
    Logger.log("The Email Notification is NOT turned ON. System will Exit.");
    exit 
  } 

  //Get the total number of filled row in the sheet.
  var currentRowAT = 2;
  var currentCellValueAT = "start";
  while (currentCellValueAT != ""){
    if (currentCellValueAT = birthdaysSheet.getRange("G" + currentRowAT).getValue() != ""){
    currentRowAT = currentRowAT +1;
    }
  }
  var birthdaysSheetLastRow = currentRowAT - 1;

  // Get today's Date (with Month, Date and Year)
  var today = new Date();
  var todayMth = today.getMonth()+1;
  var todayDate = today.getDate();
  var todayYear = today.getFullYear();


  // Check sheet cell for match to alertDate, k is the current row number being checked. Starting at 2 as the row #1 is for the headers
  for (k=2; k < birthdaysSheetLastRow + 1; k++)
  {
     var targetBday = new Date();
     targetBday = birthdaysSheet.getRange("P" + k).getValue();

     // If Birthday is not speicified, continue with the next row
     if (targetBday == ""){continue};

     var unadjTargetBday = new Date();
     var unadjTargetBdayMth = targetBday.getMonth()+1;
     var unadjTargetBdayDate = targetBday.getDate();
     var unadjTargetBdayYear = targetBday.getFullYear();
     var unadjTargetBday = targetBday;


     targetBday.setDate(targetBday.getDate()-daysInAdvance); // Calculating how many days in advance you want to trigger the notification. This is set in Settings Tab.
     var targetBdayMth = targetBday.getMonth()+1;
     var targetBdayDate = targetBday.getDate();

     if (targetBdayMth + " " + targetBdayDate == todayMth + " " + todayDate)
     {
       var targetBirthDateYearsOld = (today.getYear() - unadjTargetBday.getYear())-1900;
       prepareAndSendEmail(k, targetBirthDateYearsOld);       
     }
   } 
}
like image 894
user1413 Avatar asked Jun 16 '26 08:06

user1413


1 Answers

getValue will return the type string/date/number depending on the cell type in the spreadsheet (see menu Format -> Number). To be sure, just always convert to Date Type. This is the right way to convert it:

var targetBday = new Date(birthdaysSheet.getRange("P" + k).getValue());
like image 63
Wim den Herder Avatar answered Jun 17 '26 23:06

Wim den Herder