Skip to content

Instantly share code, notes, and snippets.

@davidboy
Created November 14, 2015 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidboy/19863932608dbb6d4a34 to your computer and use it in GitHub Desktop.
Save davidboy/19863932608dbb6d4a34 to your computer and use it in GitHub Desktop.
function onEdit() {
var cell = SpreadsheetApp.getActiveSheet().getActiveCell();
switch (cell.getColumn()) {
case 2:
insertTimestamp(cell, 'C');
break;
case 4:
insertTimestamp(cell, 'E');
break;
case 7:
insertTimestamp(cell, 'H');
break;
case 9:
insertTimestamp(cell, 'J');
break;
}
}
function insertTimestamp(modifiedCell, timestampColumn) {
var row = modifiedCell.getRow();
var offset = "GMT-"+Math.floor((new Date()).getTimezoneOffset() / 60);
var time = Utilities.formatDate(new Date(), offset, "hh:mm a");
SpreadsheetApp.getActiveSheet().getRange(timestampColumn + row.toString()).setValue(time);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment