In my Google Sheets, I am using a script TIMESTAMP for function NOW() is updating when I open the Google Sheet to check the file
that is been given to me by Tanaike that retrieves time and date from the selection of a dropdown list in column D to column E.
capture1
From your showing sample output situation, how about using Utilities.formatDate
as follows?
In this case, when you want to put the value as the string value, how about modifying TIMESTAMP
as follows?
function TIMESTAMP() {
return Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'HH:mm:ss:SSS" - "dd/MM');
}
If you want to put the value as the date object, how about modifying onEdit
as follows? I think that this might be the same direction as TheMaster's comment. Ref
function onEdit(e) {
const excludeSheetNames = ["START", "MASTER"]; // Please set exclude sheet names.
const { range } = e;
const sheet = range.getSheet();
if (excludeSheetNames.includes(sheet.getSheetName()) || range.columnStart != 4 || range.rowStart == 1) return;
range.offset(0, 1).setNumberFormat('HH:mm:ss:SSS" - "dd/MM').setValue(new Date());
if (e.value != "TRUE") return;
e.source.getActiveSheet().getRange(e.range.rowStart, e.range.columnStart + 1).setValue(new Date()).setNumberFormat('HH:MM:SS - dd/MM ');
}
TIMESTAMP
is not used. The number format is changed and the date object is put into the cell.