1

I have a google sheet with a column that has a data that looks like this.

8/31/2017 11:45:41

and that format is Date Time

now when Im using the google code .getValues and display it in Logger.log

this is the output

Fri Sep 01 02:45:41 GMT+08:00 2017

My Question is How can I get the value as it is? I dont want to get it as time stamp I want the format like 8/31/2017 11:45:41 or M/D/YYYY HH:MM:SS really same as what it displays in sheet.

here is my code.

//Convert Timestamp to M/D/YYYY HH:mm:ss
function ConvertToYMDHS(inputFormat){
  var userTimeZone = CalendarApp.getDefaultCalendar().getTimeZone();
  return inputFormat ? Utilities.formatDate(inputFormat, "GMT-8:00", "M/d/yyyy HH:mm:ss") : "";
}

ConvertToYMDHS("Cell of the Column that has a Date");

Nardong Bagsik
  • 206
  • 2
  • 18

1 Answers1

2

How about a modification as follows?

From :

var val = SpreadsheetApp.getActiveSheet().getRange("a1").getValue();
Logger.log(val)

>>> Thu Aug 31 11:45:41 GMT+09:00 2017

To :

var val = SpreadsheetApp.getActiveSheet().getRange("a1").getDisplayValue();
Logger.log(val)

>>> 08/31/2017 11:45:41

Of course, you can also use getDisplayValues() for retrieving values from several cells as 2 dimensiolnal array.

  • The detail information of getDisplayValue() is here.

  • The detail information of getDisplayValues() is here.

If I misunderstand your question, I'm sorry.

Tanaike
  • 105,090
  • 8
  • 51
  • 83