First you need to define what you mean by 'an empty TDateTime
value'.
A TDateTime
value is a double with the date encoded in the integer part and the time encoded in the fractional part. So, the closest thing to a 'null date' you can get is probably 0
.
Hence, simply test ADate <> 0
to test if the date is 'null'.
But beware: if you declare a TDateTime
local variable then it will not necessarily be =0
before you give it a value. It can be anything. Of course, the same thing applies to variables of type integer
, double
, boolean
, ...
Also, I believe that a TDateTime
with value 0
encodes the date 1899-12-30.
Finally, negative TDateTime
values are perfectly normal. For instance, -5000
corresponds to 1886-04-22
.
I don't quite get the point of your code. If you want to use 0
as the 'unassigned' value (which is bad if you are interested in dates close to 1899-12-30), why not do simply
function IsUnassigned(ADate: TDateTime): boolean;
begin
result := ADate = 0;
end;
or, possibly (but not equivalently!),
function IsUnassigned(ADate: TDateTime): boolean;
begin
result := IsZero(Date);
end;
In his answer, ain gave a couple of more reasonable choices for the 'unassigned date' value.