Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8538911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:14:11+00:00 2026-06-11T11:14:11+00:00

I want to convert a date object into a serial number that is consistent

  • 0

I want to convert a date object into a “serial number” that is consistent with the underlying value of dates used in Google Spreadsheets. My understanding is that in Javascript the primitive value of a date object is the number of milliseconds after (or before) midnight on 1st Jan, 1970; in Google Spreadsheets, the primitive value of a date is 0 (zero) for midnight on 30th Dec, 1899, and each day thereafter equals 1 (so, for example, 7 hours is equal to 7 divided by 24).

I tried this function:

function date2Serial(date) {
  return (date.getTime() + 2209161600000) / 86400000;
  // 2209161600000 = milliseconds between 1899-12-30 and 1970-01-01
  // 86400000 = milliseconds in a day
  // question "on the side" - is there any essential difference between
  //  .getTime() and .valueOf()?
}

And this returns a value that is a bit off – and I think the “off” corresponds with my time zone difference from GMT. So even though both the Spreadsheet Settings and Project Properties are set to GMT+10 in my case, it seems that getTime() operates on GMT.

So for example:

A1: 16/09/2012 06:00:00
A2: =date2serial(A1)
A3: =VALUE(A1)

A2 returns 41167.8333, where A3 returns 41168.25.

Now I tried using the getTimezoneOffset() method, which appeared to correct the issue:

function date2Serial(date) {
  return (date.getTime() + 2209161600000 - (date.getTimezoneOffset() * 60000)) / 86400000;
}

However this relies on the Project Properties time zone being correct, as opposed to the Spreadsheet Settings time zone (it is actually possible to set each of these differently).

My question:

Is this behaviour expected, and the “adjustment” for time zone necessary? Or should the getTime() (and all the other methods like getHours(), getMinutes() and so on) operate on the user’s set time zone rather than GMT/UTC, and the “adjustment” is actually a workaround for a bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:14:12+00:00Added an answer on June 11, 2026 at 11:14 am

    getTime() returns a time duration, not a moment in time and therefore does not have a time zone. The reference moment to substract is midnight of January 1, 1970 (UTC).

    Methods like getHours(), getMinutes() and so on give part of a moment in time. The result is dependent on the time zone of the date object used. If you want to be independent of the date objects’ time zone you should use getUTCHours(), getUTCMinutes() and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert a String Date into a DateTime object for a particular
I have strings like 84, 03 etc. that I want to convert to Date
I want to convert a string like 2012-03-08T00:00:00+01:00 into Date.. I tried to use
I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @MMM dd,
so I have a variable containing a date object. I want to convert it
I want to convert a date string to a date object in jQuery, and
How do I convert this timestamp from php into a javascript Date() object? This
Having this string 30/11/2011 . I want to convert it to date object. Do
I want to convert '2011-10-13' to a date object representing the same. I use
I want to convert String to Date in different formats. For example, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.