Skip to content

Instantly share code, notes, and snippets.

@aflansburg
Created October 31, 2017 16:27
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/a0620fe9b79a97b05c9c9d74bc536ae5 to your computer and use it in GitHub Desktop.
Save aflansburg/a0620fe9b79a97b05c9c9d74bc536ae5 to your computer and use it in GitHub Desktop.
Timestamp and user stamp last update on a google sheet
function timestampIt(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; // this will assign the first sheet
var cell = sheet.getRange('A1');
var d = new Date();
d.setHours(d.getHours() +1);
var user = Session.getActiveUser().getUserLoginId();
user = String(user);
user = user.replace('@gmail.com', '');
cell.setValue('Last updated: ' + d.toLocaleString() + ' by ' + user);
}
@aflansburg
Copy link
Author

Had to add an hour to the date variable as, for some reason, the script was returning the time -1, most likely due to some client side issue with DST (<-- who needs it anyways). var d = new Date(); d.setHours(d.getHours() +1);

@kurddata2006
Copy link

kurddata2006 commented Sep 17, 2020

Thanks , But the user ID will not print in cell , I must run the script in script editor to print user ID in sheet . strange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment