// Sheets

Auto-fill the date when a row is edited in Google Sheets.

Stamp today's date into column B the instant column A gets a value — without writing into already-stamped rows. Pure onEdit trigger; nothing leaves the sheet.

When I add a new entry I want the timestamp to fill itself. I'm tired of typing =NOW() and pasting as value.

The script

copy · paste · trigger
autoFillDateOnEdit.gs
Apps Script
// Installable onEdit trigger. When a value lands in column A,
// stamp today's date into column B (only if B is empty so existing
// timestamps aren't overwritten on re-edit).
function onEdit(e) {
  const range = e.range;
  if (range.getColumn() !== 1) return;  // only column A
  if (range.getRow() === 1) return;     // skip header row
  if (!range.getValue()) return;        // ignore deletions

  const dateCell = range.offset(0, 1);  // adjacent column B
  if (!dateCell.getValue()) {
    dateCell.setValue(new Date());
  }
}

Need a variant? Gnaw writes a custom version from one sentence — fields, triggers, edge cases handled.

Walkthrough

How it works

Apps Script ships two onEdit variants. The simple trigger (just a function named onEdit) fires on every edit but can't write to other documents. The installable trigger has the same name but is added explicitly via the Triggers panel — it can do almost anything.

For this script the simple trigger is enough: we only write within the same sheet. Apps Script auto-detects the function name and wires it up.

The three guards (column check, header check, deletion check) keep the trigger from firing on irrelevant edits. The B-cell-empty check makes the function idempotent — editing column A in an existing row won't overwrite a date that's already there.

How to install

Paste the function into Extensions → Apps Script for the sheet. Save. That's it — the simple onEdit trigger fires automatically on the next edit. No "Add Trigger" step needed.

If you ever need to write into a different sheet (e.g. mirror the timestamp into a log workbook), switch to an installable onEdit trigger via the Triggers panel — same function body works.

Tweaking the columns

Watch a different column: change the `getColumn() !== 1` check.

Stamp into a different column: change `range.offset(0, 1)` (the second argument is the column delta — 1 = right by one, 2 = right by two, -1 = left by one).

Stamp the time without the date: replace `new Date()` with `new Date().toLocaleTimeString()`.

Want a custom version?

Describe your sheet and the rule you want. Gnaw writes the Apps Script — fields, triggers, edge cases — in one shot.

FAQ

4 questions
Why doesn't the date update when I change column A again?
By design — the script checks if column B already has a value and skips if so. Remove the `if (!dateCell.getValue())` block to make every edit re-stamp.
Can I do this with a formula instead?
=NOW() in column B works, but it volatilises — every recalculation moves every timestamp. Apps Script writes a static value that survives recalc.
Will this work in shared sheets with multiple editors?
Yes. Each editor's edit fires the trigger under their own credentials. The stamps reflect "when the row was first edited," not who.
How do I capture the editor's email too?
Switch to an installable onEdit trigger and use Session.getActiveUser().getEmail() inside the handler. The simple trigger can't read user identity.