I am currently using the following code in Google scripts, but it only displays the date.
How can I add the hh:mm:ss to the value when I type "_now"?
function onEdit(e) {
if (e.range.getValue() == "_now") {
e.range.setValue(new Date());
}
}
I am currently using the following code in Google scripts, but it only displays the date.
How can I add the hh:mm:ss to the value when I type "_now"?
function onEdit(e) {
if (e.range.getValue() == "_now") {
e.range.setValue(new Date());
}
}
The script actually does set both date and time. The reason you don't see it is that the cell is formatted to show only the date.
You can either change its format manually, or do it within the script:
function onEdit(e) {
if (e.range.getValue() == "_now") {
e.range.setValue(new Date()).setNumberFormat("yyyy-MM-dd HH:mm:ss");
}
}
if you want the ISO standard 2016-12-25, or
function onEdit(e) {
if (e.range.getValue() == "_now") {
e.range.setValue(new Date()).setNumberFormat("MM/dd/yyyy HH:mm:ss");
}
}
if you prefer 12/25/2016 instead.