Skip to content

Instantly share code, notes, and snippets.

@umjammer
Created January 6, 2015 09:17
Show Gist options
  • Save umjammer/cafbc1286093e3706258 to your computer and use it in GitHub Desktop.
Save umjammer/cafbc1286093e3706258 to your computer and use it in GitHub Desktop.
coloring sunday and saturday on datetime columns on google spreadsheet
/**
*/
function colorRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var range = sheet.getRange(2, 1, sheet.getLastRow());
var check = range.getValues();
for (var i = 1; i < numRows - 2; i++) {
var weekday = (((new Date(check[i][0]).getDay()) + 6) % 7) + 1;
Logger.log(weekday);
if (weekday == 6) {
sheet.getRange(i + 1, 1).setBackground("#ccccff");
} else if (weekday == 7) {
sheet.getRange(i + 1, 1).setBackground("#ffcccc");
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment