GAS AI BuilderApps Script Assistant Sign in

Stamp the time when a row is edited

Apps Script recipes › Triggers and long jobs

An onEdit function writes the time into an "Updated" column whenever someone edits that row.

File Code.gs

function onEdit(e) {
  const sheet = e.range.getSheet();
  if (sheet.getName() !== 'Items' || e.range.getRow() < 2) return;
  const header = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
  const col = header.indexOf('Updated') + 1;
  if (!col || e.range.getColumn() === col) return;
  sheet.getRange(e.range.getRow(), col, e.range.getNumRows(), 1).setValue(new Date());
}

Good to know

Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.

Use it in a project

More in Triggers and long jobs

Finish a long job in parts (6-minute limit)Works through rows until about 5 minutes have passed, remembers where it stopped, and schedules itself to go on.Run a function every day at a set hourInstalls one time trigger for a function, removing older ones for it first so it never runs twice.