Purpose: To extract date and time from a sheet (created by filled google forms) and use them in the body of email to be set automatically using the script. Script editor code:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 16; // First row of data to process
var numRows = 1; // Number of rows to process
for( var j=startRow; j<startRow + numRows; j++)
{
var color = sheet.getRange(j, 10).getBackground();
if("#00ff00"==color)
{
// Fetch the range of cells A2:B3
var row = sheet.getSheetValues(j, 1, 1, 14); //extract j th row till 14/Nth col
var nameStudent = row[0][0] +" "+row[0][1];
var time = row[0][6]+" on ";// +row[0][7]+" at "+row[0][8];
var nameRecipient="Dear "+row[0][9]+",";
var emailRecipient=row[0][13];
var subject= "Date and time "+row[0][5]+" at "+row[0][6];
var message=nameRecipient+sheet.getRange("L11").getValue()+nameStudent+sheet.getRange("M11").getValue()+time+nameStudent+sheet.getRange("N11").getValue();
MailApp.sendEmail(emailRecipient, subject, message);
sheet.getRange(j,10).setBackground("#ff9900");
}
}
}
In output (i.e. email):
The date is entered by person filling google form. I'm accessing the google sheet created using the forms. Screenshot of the sheet: https://drive.google.com/file/d/0B2hiq6P5ceD-aUZQTDBVUXJYbEk/edit?usp=sharing The cell (when double clicked) opens a calender shown in the above linked screenshot. I use the following code (Using Google Apps Script) to get a row from the sheet:
var row = sheet.getSheetValues(j, 1, 1, 14); //extract j th row till 14/Nth col
In the debugger the date looks like:
[["Gaaav", "Budapest","[email protected]", 9823527827, "San Francisco International Airport(SFO)", 41855, 0.5277777777810115,"Si016", "Al02", "Yaar", "pr", "3112", 94984802569, "[email protected]"]]
In the above statement the number 41855 is the date. It actually is 8/4/2014 . But I can't read it . Neither can I read the time, which in the above debug o/p, is 0.5277777777810115.
I'm attaching a screenshot of the debug screen:
https://drive.google.com/file/d/0B2hiq6P5ceD-aFlDd2g4SlM5MW8/edit?usp=sharing

