Consider the following code:
procedure Test; function d1: Variant; var DDt: TDateTime; begin DDt := EncodeDate(100,1,1); Result := DDt; end; function d2: Variant; var DDt: TDateTime; begin DDt := EncodeDate(99,12,31); Result := DDt; end; procedure Writedate(V: Variant); begin Writeln(string(V)); end; var V: Variant; begin V := d1; Writedate(V); V := d2; Writedate(V); end;
The first Writedate call will succeed, and the exit will be '01-01-01-0100 '. The second call, however, will fail with an "invalid argument" error. When checking the code, you can see that Variant dates 99-12-31 has an EVariantInvalidArgError error.
However, if I call FormatDateTime('c', TDateTime(V)) on TDateTime , they will both succeed. In fact, at any time when Variant contains a TDateTime whose date precedes 100 CE, the IDE will display an EVariantInvalidArgError when checking its value.
It seems strange that Variant cannot handle dates up to 100 CE when TDateTime can. Is this a bug in Delphi? I believe that it is right between 99 and 100 years CE to be a little suspicious.
source share