A TDateTime
values can be thought of as containing two distinct parts: the date part and the time part. The CompareTime
function only compares the time part and ignores the date part. The documentation says:
Indicates the relationship between the time portions of two TDateTime
values.
Call CompareTime to compare the two TDateTime values specified by A
and B. CompareTime returns:
- LessThanValue if A occurs earlier in the day than B (even if A occurs on a later day than B).
- EqualsValue if A occurs at the same time of day as B, ignoring the date portion of the two values.
- GreaterThanValue if A occurs later in the day than B (even if A occurs on an earlier day than B).
You want to compare the entire date time value. To do that you should use CompareDateTime
. One important note in the documentation for the function states:
Note: CompareDateTime differs from a direct comparison of the corresponding double precision values in that two TDateTime values are
considered the same if they have the same value down to the
millisecond. It is possible to create two TDateTime values that differ
numerically when viewed as doubles, but which represent the same year,
month, day, hour, minute, second, and millisecond.