title: Capture date & time when cell is edited (google spreadsheet)
body: <p>I'm looking for a way to capture time &amp; date (or maybe date only) when a cell is updated/edited.</p>
  
  <p>I found some tutorials while searching through the web, but I guess its a little outdated that it doesn't run 100%. here is the code I found</p>
  
  <pre><code>function capdatetime(event)
  {
  var timezone = "GMT+8";
  var timestamp_format = "MM-dd-yyyy"; //Timestamp format
  var updateColName = "Date Sent";
  var sheet = SpreadsheetApp.getActiveSpreadsheet(); //Name of the sheet where you want to run the script
  var actRng = SpreadsheetApp.getActiveRange();
  var editColumn = actRng.getColumn();
  var index = actRng.getRowIndex();
  var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
  var dateCol = headers[0].indexOf(timeStampColName);
  var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
  if (dateCol &gt; -1 &amp;&amp; index &gt; 1 &amp;&amp; editColumn == updateCol) { //only timestamp of 'Last Updated' header exists, but not in the header row itself!
  var cell = sheet.getRange(index, dateCol + 1);
  var date = Utilities.formatDate(new date(), timezone, timestamp_format);
  cell.setValue(date);
  }
  }
  </code></pre>
  
  <p>I modified this to address some errors I encountered but there's one particular error that I can't understand that much.</p>
  
  <p>here is the error:
  <a href="https://i.stack.imgur.com/FGqZl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FGqZl.png" alt="enter image description here"></a></p>
  
  <p>can someone explain and help me with this? thanks, I'll also continue searching for some ideas.</p>