2

If we have only a time in say cell A1 of Google sheets. For example, I have this:

8:09:00 AM

When I use this to fetch the contents of the cell: sheet.getRange(1, 1).getValue(); this is what it returns:

Sat Dec 30 1899 08:09:00 GMT-0500 (EST)

Why is this happening? Any way for getvalue() to stop interpreting the data and get the raw data instead?

Note: No special formatting has been set by me for the cell. So I guess the formating is the default (automatic), which is not something I want to change for every cell containing such data. The cells containing such times will not be known apriori in any case.

Sujay Phadke
  • 2,145
  • 1
  • 22
  • 41

1 Answers1

9

Use range.getDisplayValue() to get the display value as a string.

More details on this can be found here: Difference between getValue() and getDisplayValue() on google app script

In short, getvalues returns an object which can be a number,a date or a string. In this case it returns a date object, which why it get formatted differently.

Community
  • 1
  • 1
Jack Brown
  • 5,802
  • 2
  • 12
  • 27