How to convert a double value to a DateTime in c#?

fifamaniac04 picture fifamaniac04 · Dec 17, 2012 · Viewed 49k times · Source

I have the value 40880.051388 and am storing it as a double, if I open Excel and paste in a cell and apply the following custom format "m/d/yyyy h:mm" to that cell, I get "12/3/2011 1:14"

How can I do this parsing/Conversion in C#? I don't know if the value is milliseconds from a certain checkpoint, like epoch time, or if the value is in some specific prepared format, but how does excel come up with this particular value? Can it be done in C#?

I've tried working with TimeSpan, DateTime, and other like things in Visual Studio but am not getting anywhere.

Answer

Jaime Torres picture Jaime Torres · Dec 17, 2012

Looks like you're using the old OLE Automation date. Use

DateTime.FromOADate(myDouble)