Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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");
share|improve this question

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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