The following code was almost exactly what I was looking for to timestamp the adjacent cell after being edited. However, I need to incorporate the currnet date as well as time. The code below gives a date "1899".

What do I need to edit or is there a better code?

function onEdit() {
    var s = SpreadsheetApp.getActiveSheet();
    if ( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
        var r = s.getActiveCell();
        if ( r.getColumn() == 13 ) { //checks the column
            var nextCell = r.offset(0, 1);
            if ( nextCell.getValue() === '' ) //is empty?
                var time = new Date();
                time = Utilities.formatDate(time, "GMT", "HH:mm:ss");

1 Answer 1


If you need to display date along with the timestamp, then look at this line:

time = Utilities.formatDate(time, "GMT", "HH:mm:ss");

You can set this to whatever you like, in the year case try this:

time = Utilities.formatDate(time, "GMT-08:00", "MM/DD/yy, hh:mm:ss");

If you are only concerned about displaying the year, then replace the MM/DD/yy info with just yyyy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.