1

I have a list of dates in the format of 44303.02359 and google sheets is able to determine that it's 4/17/2021 but javascript new Date() is unable to, it thinks it's in 1969. My google search for "Two number date separated with a period" isn't proving helpful.

What format is this? How can I parse it with javascript?

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
  • I don't think this should be closed because I was unable to find the specific answer on google or stack overflow due to not knowing the nomenclature of the date. I'm sure others will run into the same scenario. As a result, this should remain open due to the difference in question text / search specificity. It is not quite a duplicate question, only a duplicate answer. – Kevin Danikowski Apr 08 '23 at 14:50
  • 2
    That doesn't mean the question needs to stay open. It's been closed as a _duplicate_, which means it can stay here as a signpost leading to the other question. – ChrisGPT was on strike Apr 08 '23 at 20:37
  • 1
    @Chris gotcha, i wasn't aware it worked that way actually, thanks for letting me know! – Kevin Danikowski Apr 08 '23 at 23:23

1 Answers1

1

It is an Excel date "serial number"

By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.

Source: https://support.microsoft.com/en-us/office/datevalue-function-df8b07d4-7761-4a93-bc33-b7471bbff252

There is a great short converter function

function ExcelDateToJSDate(date) {
    return new Date(Math.round((date - 25569)*86400*1000));
}

Source: https://stackoverflow.com/a/22352911/7549483

ProfDFrancis
  • 8,816
  • 1
  • 17
  • 26
  • If a question is a duplicate, you should close it as such. This answer doesn't mention other issues with serial date values such as the leap year problem (so 1 represents 31 Dec 1899, not 1 Jan 1900) and dates prior to 1 Jan 1900. Also, this makes no mention that the code is suitable only for UTC. – RobG Apr 07 '23 at 08:55