0

This is what i tried

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Farm" ) { //checks that we're on Sheet1 or not
    var r = s.getActiveCell();
    if( r.getColumn() == 5 ) { //checks that the cell being edited is in column A
      var nextCell = r.offset(0, -3);
      if( nextCell.getValue() === '' ) //checks if the adjacent cell is empty or not?
        nextCell.setValue(new Date()); 
      {
        var time = new Date();
        time = Utilities.formatDate(time, "", "dd-mm-yyyy' '");
        nextCell.setValue(time);
      }
    }
  }
}

I want to type something in column E and have the date in column B, I want this to be static like a timestamp. I'm super new to coding/scripting. Anyone know how to remove the hh:mm:ss from the date?

Iamblichus
  • 18,540
  • 2
  • 11
  • 27
ShadXn
  • 1
  • 2
    Does this answer your question? [Google Apps Script date format issue (Utilities.formatDate)](https://stackoverflow.com/questions/28956532/google-apps-script-date-format-issue-utilities-formatdate) – Marios Sep 23 '20 at 18:03

1 Answers1

0

Instead of using formatDate(), you can also try setting the number format to 'nextCell'.

var time = new Date();
nextCell.setValue(time).setNumberFormat("dd-mm-yyyy");
JPV
  • 26,499
  • 4
  • 33
  • 48