I have a column in my sheet with a custom date format. The format is set on the entire column. If put a date value in the column from within sheets it shows formatted the way I specified. But if I append a new row using Google Apps Scripts it will not obey the formatting.
Before adding a row through Google Apps Script:
| Timestamp | Message |
|---------------------------|---------|
| 2019-01-01 @ 13:12:32.013 | test |
After adding a row:
| Timestamp | Message |
|---------------------------|---------|
| 2019-01-01 @ 13:12:32.013 | test |
| 1/2/2019 14:51:31 | test2 |
Google Apps Script code to add the row:
SpreadsheetApp.getActiveSheet().appendRow([new Date(), "test2"])
Is there a way to get the date to be added in a way Sheets will format it per the formatting rule?
The only way I have found is converting the data to an integer representing the number of days since 1899-12-30 but this seems very hacky.
var dateSerial = ((new Date()) - (new Date(1899, 11, 30))) / 1000 / 60 / 60 / 24;