(Background) I have a program that is using a parameterised query on a database searching on time of day. The required functionality means that I do some searches where the time is the end of the day so I natural have code like the following
Query.Parameters[3].Value := TimeOf(EnfOfTheDay(ToTime));
This fails with a formatting error because the time comes through as "31/12/1899". This is demonstrated by the following console program which outputs "31/12/1899" on the system console (or the equivalent in your regional settings).
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.DateUtils;
var
V: variant;
Time: TDateTime;
begin
Time := TimeOf(EndOfTheDay(EncodeDate(2017,1,26)));
V := Time;
Write(Output, V);
ReadLn;
end.
This is easy enough to work around but my question is whether this is a fault that should be reported to Embarcadero. I can see that the problem specifically occurs when a time only value in a TDateTime type is stored into a variant which is then coerced to text. Times earlier in the day work fine yielding strings like "23:59".
If I change the Time variable to a TTime then the resulting string is the numeric fraction (ie the Variant hasn't been set up as a datetime value) but I don't understand why the particular fraction equal to 23:59:59 (which is what EndOfTheDay generates) is interpreted as the 1899 date. I'm innately suspicious of anything yielding 1899 rollover dates because of the special issues with Microsoft products that may mean this is intentional.