I have copied and pasted your code to put a time stamp on a spreadsheet that I am working on and it is working great. Except the day is coming back as "56" for some reason and I don't know why. It gives me this-02/56/16, 06:56:03 Also the time is way off from what my actual time is. Can you let me know what I need to change to get it to work properly? Below is the code that I am using.

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-08:00", "MM/DD/yy, hh:mm:ss");
    SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
  • 1
    The time zone settings for the script and the spreadsheet are set individually. Your script can have a different time zone than your spreadsheet. Check the time zone settings in your script using the menu, File, Project Properties. In the first tab, Info, at the bottom. – Alan Wells Feb 26 '16 at 4:24
  • Welcome to Web Applications. Add the link the post from where you took the code and create a demo spreadsheet including your code to help us to reproduce the problem in order to help you with a concise answer. – Rubén Feb 26 '16 at 13:57
  • 1
    Whose code? There are a number of active volunteers offering answers here. – ale Feb 26 '16 at 14:11
  • 1
    Here is a link to a copy of the project that I am working on, any help that you can provide will be greatly appreciated.....docs.google.com/spreadsheets/d/… – Scott Miller Feb 26 '16 at 14:32
  • I'm sorry I am new to using the Stack Exchange and I can't find the spot where I copied the code from so I can't figure out who's code it is. – Scott Miller Feb 26 '16 at 15:20

Please use lower case ds, ie for Line 7:

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

GAS uses Java SE SimpleDateFormat class, where D is Day in year.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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