0

I looked at the previous posts and suggestions but i cant seem to get it working. For the moment this is my code:

function onEdit(e) {
  addTimestamp(e);
}

function addTimestamp(e){
var row = e.range.getRow();
var col = e.range.getColumn();
var width = e.range.getNumRows();
var startRow = 2 ;
var ws =  e.source.getActiveSheet().getName();
var minDismount = 0 ;


if(col == 14 || col == 23 && row >= startRow && ws == "LOTO-A" && e.source.getActiveCell().getValue() > minDismount ){
  e.source.getActiveSheet().getRange(row,col+1,width).setValue(new Date());
}

it returns "20/03/2023 5:00:00" I want to remove the "5:00:00"

Could someone please help me, i'm not a programmer so please be gentle.

Thank you

I tried new Date(new Date().toDateString()); and <any-date-object>.getDateWithoutTime();

  • Have you tried `.setValue(new Date().toLocaleDateString('en-GB'))`? – Unmitigated Mar 20 '23 at 14:54
  • @Unmitigated yes that doesnt work, it still returns "20-3-2023 5:00:00" – Twogreedy Mar 20 '23 at 15:06
  • Did you use that code exactly? Don't wrap it in a new Date. In any case, I can't reproduce the issue; it gives the correct result here: https://jsfiddle.net/yqemzwdo/ – Unmitigated Mar 20 '23 at 15:07
  • @Unmitigated: yes i see that it works with you. I tried again: if(col == 14 || col == 23 && row >= startRow && ws == "LOTO-A" && e.source.getActiveCell().getValue() > minDismount ){ e.source.getActiveSheet().getRange(row,col+1,width).setValue(new Date().toLocaleDateString('en-GB')); } and it doesnt work with me. – Twogreedy Mar 20 '23 at 15:27
  • Maybe you noticed but the code is running in a google sheet. When you adjust cell X then the datestamp occurs in cell Y (preferably without a time). – Twogreedy Mar 20 '23 at 15:33

1 Answers1

-1
new Date().toISOString().split('T')[0]
Oriol Vilaseca
  • 317
  • 3
  • 7
  • sorry doesnt work: '.setValue(new Date().toISOString().split('T')[0]);' – Twogreedy Mar 20 '23 at 15:54
  • Can you check the value on the console? if(col == 14 || col == 23 && row >= startRow && ws == "LOTO-A" && e.source.getActiveCell().getValue() > minDismount ){ var today = new Date().toISOString().split('T')[0]; console.log(today); e.source.getActiveSheet().getRange(row,col+1,width).setValue(today); } – Oriol Vilaseca Mar 20 '23 at 16:02
  • i'm really sorry but i dont know what you mean with console? I copied your latest code in the google apps script. It works but still gives the curren time "20-3-2023 17:10:06". i understand it must be frustrating talking to a newbie... – Twogreedy Mar 20 '23 at 16:12
  • All browsers have a developper console, are you running this code on a browser? Apparently not, I never heard of Google Apps Script, I don't know how to debug there. – Oriol Vilaseca Mar 20 '23 at 16:18
  • You may look here: https://stackoverflow.com/questions/24894648/get-today-date-in-google-apps-script – Oriol Vilaseca Mar 20 '23 at 16:23
  • 1
    Please read "[answer]" and "[Explaining entirely code-based answers](https://meta.stackoverflow.com/q/392712/128421)". It helps more if you supply an explanation why this is the preferred solution and explain how it works. We want to educate, not just provide code. – the Tin Man Mar 20 '23 at 23:55