I can't get the time-stamp format in a spreadsheet cell to also include the time. Currently, it only produces the date. What do I need to change to get the time-stamp to show both date and time?
Like this:
3/17/2015 10:57:45
function onEdit(event)
{
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(r.getColumn() == 8){ //To check if update cell in Column, 1 means first column.
if(r.getValue() == "Resolved"){ //To check the value is equal to Resolved
ss.getRange('L'+r.getRow()).setValue(new Date()); //Set column B1 value to current date.
date = Utilities.formatDate(time, "GMT", "HH:mm:ss");
}else{
ss.getRange('L'+r.getRow()).setValue('');
}
}
You need to use:
var formattedDate = Utilities.formatDate(time, "GMT", "MM-dd-yyyy HH:mm:ss");
There is an example in the documentation:
Google Documentation - formatDate
In you code, get the time zone of the script like this:
var timeZone = Session.getScriptTimeZone();
date = Utilities.formatDate(new Date(), timeZone, "MM-dd-yyyy | HH:mm:ss");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With