Home > front end >  How to calculate days since 1900 generated by excel date?
How to calculate days since 1900 generated by excel date?

Time:12-08

Excel is converting the date 03/11/2021 to value 44535, that seems to be days since 1900. I´m trying to figure out a way to calculate this using the own golang libs. Anyone has this kind of problem?

Thank a lot for help

CodePudding user response:

A not so fency workaround for this problem would be addDays

d := time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
fmt.Println(d) // 1900-01-01 00:00:00  0000 UTC

d2 := d.AddDate(0, 0, 44503)
fmt.Println(d2) // 2021-11-05 00:00:00  0000 UTC

Would print: 05/11/2021 witch is 2 days more than what we desire.

Here we can see the same using JavaScript:

date = new Date(1900, 0, 1)
// Mon Jan 01 1900 00:00:00 GMT-0338 (Amazon Standard Time)
date.setDate(date.getDate()   44503)
// Fri Nov 05 2021 00:00:00 GMT-0400 (Amazon Standard Time)

After some research about this 2 days I found this in a comment by @chux-reinstate-monica:

If you choose to use MS Excel to check your work note 2 things: 1) Jan 1, 1900 is day 1 (not the number of days since Jan 1, 1900) and 2) according to Excel Feb 29, 1900 exists(a bug in their code they refuse to fix.)

So we can substract 2 days from that to have: 03/11/2021.

  • Related