0

How do I add a timestamp in the format hh:mm:ss in column B (instead of "null")

  const values = [[new Date(), null, text]];
  const firstBlankCell = sheet.getRange(sheet.getLastRow() + 1, 1);
  firstBlankCell
    .offset(0, 0, values.length, values[0].length)
    .setValues(values)
    .setNumberFormat('dd.MM.yyyy');

I have tried having new Date() again instead of null but then I can't get it to have a different format from the first instance.

1
  • Welcome to Web Applications. Please show what you have tried to do what is being asked and a brief description of your search efforts as is suggested in How to Ask.
    – Rubén
    May 27 at 21:13

1 Answer 1

1

Instead of setNumberFormat use setNumberFormats, i.e.

firstBlankCell
    .offset(0, 0, values.length, values[0].length)
    .setValues(values)
    .setNumberFormats([['dd.MM.yyyy','hh:mm:ss', '0']]);

Reference

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.