We have started receiving csv (text) files with dates being represent as integers. I opened up the file in Excel and formatted the number as a date. (Highlight column, right-click, select format cell, etc....)
In a C# .NET 6.0 console program, I wanted to verify/duplicate the Excel date using the following code:
DateOnly d1 = new DateOnly(1900, 1,1);
DateOnly d2 = d1.AddDays(45108); //45114, 45126, 45108
Console.WriteLine(d2.ToString());
My C# program gives a date that is 2 days later than Excel.
int | Excel | C# |
---|---|---|
45114 | 7/7/2023 | 7/9/2023 |
45126 | 7/19/2023 | 7/21/2023 |
45108 | 7/1/2023 | 7/3/2023 |
Which is correct: C# or Excel? I need to code the conversion in c# for internal use. I would like to understand the discrepancy.