« First Trip On TransitE2328 Linker error while emitting metadata »

Converting TDateTimes to System.DateTimes and back


  01:41:56 pm, by Nimble   , 102 words  
Categories: Programming

Converting TDateTimes to System.DateTimes and back

It's not straight-up obvious how to convert the Borland and Microsoft formats back and forth in code, but it does end up being pretty easy.

TDateTimes are in "OA" format, which is OLE/COM-compatible. The functions that convert back and forth to the OLE format work just fine for TDateTimes as well.

MSDate := DateTime.FromOADate(BorlandDate);
BorlandDate := MSDate.ToOADate();

The syntax is nigh identical on the C# side apart from the assignment operator (= instead of :=).

Note that if the TDateTime arrives as an object in C# somewhere, you can simply cast it as a double; you do not need to cast it specifically as a TDateTime.

No feedback yet