Convert CkDateTime to Delphi TDateTime
Question: Which is the best way to convert a CkDateTime to a Delphi TDateTime?
Answer: I didn’t know the answer, so I Googled “Delphi TDateTime” to see exactly what it is. It brought me to this web page: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_TDateTime.html
In Delphi, TDateTime is a type that maps to a Double. In C++, the TDateTime class corresponds to the Delphi TDateTime type.
The integral part of a Delphi TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of the TDateTime value is fraction of a 24 hour day that has elapsed.
My experience tells me that anytime you see a date/time represented as a double, you have an OLE Date. (Google “ole date format”)
The CkDateTime’s GetAsOleDate function returns an OLE date. It should be just a matter of setting the Delphi TDateTime equal to the double returned by GetAsOleDate:
var dt: HCkDateTime; bLocal: Boolean; // Delphi TDateTime (which is just a Double) ddt: TDateTime; begin dt := CkDateTime_Create(); bLocal := True; ddt := CkDateTime_GetAsOleDate(dt,bLocal); CkDateTime_Dispose(dt);