Sujay Phadke
Sujay Phadke

Reputation: 2196

getvalues() returns a complete date in the year 1899 for a cell containing only time

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.

Upvotes: 2

Views: 4270

Answers (1)

Jack Brown
Jack Brown

Reputation: 5892

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.

Upvotes: 10

Related Questions