google spreadsheet - My app keeps showing today's date and not what is in the cell I called for -


i getting output of first date of column date "exp" should be. column 3 expiration dates when call , output it shows long formatted day date , time. know little if coding. please help.

this output should except date should date from not top date sheet.

mjc-ap-200 watchguard model : ap 200is due in 10 days 09/30/17.

dma-ap-300-2 watchguard model : ap 300is due in 0 days 09/30/17.

elwood properties watchguard model : wgd-wg026583is due in 0 days 09/30/17.

elwood prop-xtm-26w watchguard model : xtm 26-wis due in 0 days 09/30/17.

  function checkreminder() { // spreadsheet object var spreadsheet = spreadsheetapp.getactivespreadsheet(); // set first sheet active spreadsheetapp.setactivesheet(spreadsheet.getsheets()[0]); // fetch sheet var sheet = spreadsheet.getactivesheet();  // figure out last row var lastrow = sheet.getlastrow();  // rows indexed starting @ 1, , first row // headers, start row 2 var startrow = 2;  // grab column 8 (the 'days left' column)  var range = sheet.getrange(2,8,lastrow-startrow+1,1 ); var numrows = range.getnumrows(); var days_left_values = range.getvalues();  // now, grab name column range = sheet.getrange(2, 1, lastrow-startrow+1, 1); var reminder_info_values = range.getvalues();  // now, grab exp date column range = sheet.getrange(2, 3, lastrow-startrow+1, 1); var exp = range.getvalue(); var numrows = range.getnumrows(); var exp = utilities.formatdate(exp, "gmt+1", "mm/dd/yy")  // now, grab model column range = sheet.getrange(2, 4, lastrow-startrow+1, 1); var model = range.getvalues();  var warning_count = 0; var msg = "";  // loop on days left values (var = 0; <= numrows - 1; i++) { var days_left = days_left_values[i][0]; if(days_left <= 60) {   // if it's less 60 days until due date.   var reminder_name = reminder_info_values[i][0];    msg = msg + ""+reminder_name+" watchguard model : " +model[i][0]+"is due    in "+days_left+" days "+utilities.formatdate(exp[i]   [0],"gmt+1","mm/dd/yy")+".\n \n";   warning_count++;   }   }    if(warning_count) {    mailapp.sendemail("james@mccnet.com",      "watchguard expiration list", msg);    }      }; 

by quick seems giving formatdate method new date() first parameter returns today's date. think way wanted this

var exp = utilities.formatdate(exp,"gmt+1","mm/dd/yy")  

this gives formatdate date fetched spreadsheet , proper day formatted.

try code instead:

function checkreminder() { // spreadsheet object var spreadsheet = spreadsheetapp.getactivespreadsheet(); // set first sheet active spreadsheetapp.setactivesheet(spreadsheet.getsheets()[0]); // fetch sheet var sheet = spreadsheet.getactivesheet();  // figure out last row var lastrow = sheet.getlastrow();  // rows indexed starting @ 1, , first row // headers, start row 2 var startrow = 2;  // grab column 8 (the 'days left' column)  var range = sheet.getrange(2,8,lastrow-startrow+1,1 ); var numrows = range.getnumrows(); var days_left_values = range.getvalues();  // now, grab name column range = sheet.getrange(2, 1, lastrow-startrow+1, 1); var reminder_info_values = range.getvalues();  // now, grab exp date column range = sheet.getrange(2, 3, lastrow-startrow+1, 1); var exp = range.getvalues(); var numrows = range.getnumrows();  // now, grab model column range = sheet.getrange(2, 4, lastrow-startrow+1, 1); var model = range.getvalues();  var warning_count = 0; var msg = "";  // loop on days left values (var = 0; <= numrows - 1; i++) { var days_left = days_left_values[i][0]; if(days_left <= 60) {   // if it's less 60 days until due date.   var reminder_name = reminder_info_values[i][0];    msg = msg + ""+reminder_name+" watchguard model : " +model[i][0]+"is due    in "+days_left+" days "+utilities.formatdate(exp[i]   [0],"gmt+1","mm/dd/yy")+".\n \n";   warning_count++;   }   }    if(warning_count) {    mailapp.sendemail("james@mccnet.com",      "watchguard expiration list", msg);   } }; 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -