starleaf1
starleaf1

Reputation: 2862

Convert Google Sheets date to JavaScript Date

I'm working with unformatted values received via Google Sheets REST API. One of the columns is a timestamp which only reads as a single number. Looks neither like a Unix timestamp nor JS timestamp. For example, 2020-12-09T20:55:14+08:00 comes as 44174.87168438657.

What is this format and how do I convert it to Unix timestamp or JS Date?

Upvotes: 0

Views: 514

Answers (1)

Nikko J.
Nikko J.

Reputation: 5533

SERIAL_NUMBER outputted by the API is the number of days since December 30, 1899 and the fractional portion (right of the decimal) counts the time as a fraction of the day.

You could verify the start date by using =TO_DATE in your spreadsheet.

Example:

enter image description here

To convert the serial date into a Javascript date, you could follow silkfire's comment here.

References

DateTimeRenderOption

TO_DATE()

Upvotes: 1

Related Questions