tags:

views:

280

answers:

2

How do I convert a DateTime value to a double?

+5  A: 

If, by double you mean an OLE Automation date, then you can use DateTime.ToOADate(). From the linked MSDN topic:

An OLE Automation date is implemented as a floating-point number whose value is the number of days from midnight, 30 December 1899. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

The base OLE Automation Date is midnight, 30 December 1899. The maximum OLE Automation Date is the same as MaxValue, the last moment of 31 December 9999.

If you're talking about some other date representation that can also be stored in a double, please specify...

Shog9
you beat me to it
jle
*blows smoke off finger tips*
Shog9
+2  A: 

DateTime.ToOADate() converts to a double OLE Automation Date in C#

jle