The Problem (Q-score 5, ranked #43rd of 303 in the Excel VBA archive)
The scenario as originally posted in 2012
I have a .CSV file which I am reading into a C# program. In one of the columns, there is a date, but it is in the “general” format, so it shows up in the .CSV as a number. For example: 41172.
How can I convert this number to a date with format dd/mm/yyyy in C#? 41172 is equivalent to 20/09/2012.
Why community consensus is tight on this one
Across 303 Excel VBA entries in the archive, the accepted answer here holds elite answer (top 10 %%) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — elite answer (top 10 %%) (+28)
Advisory answer — community consensus with reference links
Note: the verified answer below is a reference / advisory response rather than a copy-ready snippet.
To go from an DateTime in the “Excel Format” to a C# Date Time you can use the DateTime.FromOADate function.
In your example above:
DateTime myDate = DateTime.FromOADate(41172);
To write it out for display in the desired format, use:
myDate.ToString("dd/MM/yyyy");
If you are wondering where the discrepancies in Excel’s date handling come from, it’s supposed to be on purpose:
When Lotus 1-2-3 was first released, the program assumed that the year
1900 was a leap year even though it actually was not a leap year. This
made it easier for the program to handle leap years and caused no harm
to almost all date calculations in Lotus 1-2-3.When Microsoft Multiplan and Microsoft Excel were released, they also
assumed that 1900 was a leap year. This allowed Microsoft Multiplan
and Microsoft Excel to use the same serial date system used by Lotus
1-2-3 and provide greater compatibility with Lotus 1-2-3. Treating
1900 as a leap year also made it easier for users to move worksheets
from one program to the other.Although it is technically possible to correct this behavior so that
current versions of Microsoft Excel do not assume that 1900 is a leap
year, the disadvantages of doing so outweigh the advantages.
Source: http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
When to Use It — vintage (14+ years old, pre-2013)
Ranked #43rd in its category — specialized fit
This pattern sits in the 92% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.
What changed between 2012 and 2026
The answer is 14 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.