Skip to content

Instantly share code, notes, and snippets.

@aflansburg
Created December 7, 2017 16:39
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 aflansburg/f99ee70461706c62212e68d7b6e07419 to your computer and use it in GitHub Desktop.
Save aflansburg/f99ee70461706c62212e68d7b6e07419 to your computer and use it in GitHub Desktop.
Add a timestamp to a cell in Google Sheets (Gsheets)
function addTimestamp(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange('A1');
var d = new Date();
d.setHours(d.getHours());
var user = Session.getActiveUser().getUserLoginId();
user = String(user);
// cosmetic: this just removes the email domain from the user info
user = user.replace('@gmail.com', '');
cell.setValue('Last updated: ' + d.toLocaleString() + ' by ' + user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment