javascriptgoogle-sheetstimestampautomatic-properties

automatic timestamp script for each row


I'm looking for a script for google sheet that automatically inserts a timestamp for each row. and the date and time will be updated every time any of the rows gets edited. Timestamp will be put on column 1 and the rows can be the whole rows after the row 1, no specific number of rows. Please help I am very new at this. Need it badly. Thank you


Solution

  • You can use an onEdit trigger from Google Apps Script.

    To do that, open a script bound to your spreadsheet by clicking Tools > Script editor, copy the following code and save the project:

    function onEdit(e) {
      var row = e.range.getRow();
      if (row > 1) { // Check edited row is not first one
        var formattedDate = Utilities.formatDate(new Date(), e.source.getSpreadsheetTimeZone(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); // Format you want the timestamp, edit accordingly
        e.range.getSheet().getRange(row, 1).setValue(formattedDate);
      }
    }
    

    Reference: