Hi Community,
I want to format datetime input value on onEdit event.
ex) 2021/10/25 15:00 -> Oct 25, 2021 3:00 PM
I put the same value (2021/10/25 15:00) on the sheet.
When I get value by using SpreadsheetApp Class, it comes in with normal datetime value.
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(6, 6).getValue()But when using event object on onEdit, it comes in Num type value.
onEdit(e){Logger.log(e.value)}Is there any way to convert Number to Datetime?
I got the answer from Stack Overflow.
Using e.value cannot return Date data type, so it gets converted into Number.
You could use e.range.getValue() instead.
function onEdit(e) {Jenny,
The value returned by e.value is not incorrect, it is just not formatted correctly to be seen as a Date.
You could use the following to set it up as a Date:
Var dateValue = new Date(e.value);
The advantage of using the e params over using getValue() is that it is much faster as it does not require a poke at the spreadsheet. This is only of concern of course if you have a large amount of processing to be done and are concerned by how long the script takes to complete.
Hope this helps.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2c1fe55d-67c8-4a27-ac72-9fb9326bc097n%40googlegroups.com.