First you need to determine what you mean by "empty TDateTime ".
The value of A TDateTime is a double number with the date encoded in the integer part and the time encoded in the fractional part. So, the closest thing to a "zero date" that you can probably get is 0 .
Therefore, just test ADate <> 0 to check if the date is "null".
But be careful: if you declare a local variable, TDateTime , then it will not necessarily be =0 before you give it a value. It could be anything. Of course, the same applies to variables of type integer , double , boolean , ...
In addition, I believe that TDateTime with a value of 0 encodes the date 1899-12-30.
Finally, negative TDateTime values โโare perfectly normal. For example, -5000 corresponds to 1886-04-22 .
I do not quite understand the meaning of your code. If you want to use 0 as an โunassignedโ value (which is bad if you are interested in dates close to 1899-12-30), why not just do
function IsUnassigned(ADate: TDateTime): boolean; begin result := ADate = 0; end;
or perhaps (but not equivalent!)
function IsUnassigned(ADate: TDateTime): boolean; begin result := IsZero(Date); end;
In his answer, ain gave a couple of more reasonable solutions for the meaning of "unrecognized date".
Andreas Rejbrand
source share