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.
EDIT: As noted in comments and other answers,
DateTime.FromOADateis a much better approach. I’ll remove this answer if it’s ever unaccepted. (But, there are still platforms like .NET Core whereFromOADateis not supported so it is still useful for people using these platforms.)I suspect you want:
(See other answers for why you need to subtract 2.)