0
votes

When I am copying timestamp from one sheet to another or in the same sheet only then it is not copying the time from the timestamp. It is only copying date. See the below image -

enter image description here

Here is my code -

function myFunction() {

  var files = DriveApp.getFilesByName('myfile');
  while (files.hasNext()) {
  var file = files.next();
  var ss = SpreadsheetApp.open(file); 
  var sheet = ss.getSheets()[0];
  var lastRow = sheet.getLastRow();

  var range = sheet.getRange(1,1,lastRow,2);
  var values = range.getValues();

  Logger.log(values);

  var range = sheet.getRange(sheet.getLastRow()+1,1,lastRow, 2);
  range.setValues(values); 
  }
}

The logger contains this information -

[18-10-20 11:18:17:743 PDT] [[TIMESTAMP, EVENT], [Mon Oct 01 05:10:13 GMT+05:30 2018, Event 1], [Mon Oct 01 05:10:16 GMT+05:30 2018, Event 2], [Mon Oct 01 05:10:17 GMT+05:30 2018, Event 3], [Mon Oct 01 05:10:24 GMT+05:30 2018, Event 4], [Mon Oct 01 05:10:26 GMT+05:30 2018, Event 5], [Mon Oct 01 05:10:32 GMT+05:30 2018, Event 6], [Mon Oct 01 05:10:38 GMT+05:30 2018, Event 7], [Mon Oct 01 05:10:38 GMT+05:30 2018, Event 8], [Mon Oct 01 05:10:45 GMT+05:30 2018, Event 9], [Mon Oct 01 05:11:07 GMT+05:30 2018, Event 10]]

What could be the reason?

1
Just change the format of copied column. - TheMaster
How to change programmatically? - Irfan Alam
You tell me.... - TheMaster
If I would have known why would I have asked this question? - Irfan Alam
sheet.getRange("A:A").activate(); sheet.getActiveRangeList().setNumberFormat('M/d/yyyy H:mm:ss'); - Irfan Alam

1 Answers

0
votes

Ok. Answering my own question because I found the answer before someone answered. Just add this formatting code at the bottom to change the format of that cell to your specified format as suggested by TheMaster

sheet.getRange("A:A").activate();
sheet.getActiveRangeList().setNumberFormat('M/d/yyyy H:mm:ss');