Comparing Time Values

前端 未结 1 1855
Happy的楠姐
Happy的楠姐 2021-01-07 14:55

I want a method which compares the times, eg if Atime occurs earlier than Btime do something, I would use a CompareTime Function but my problem with this function is what is

1条回答
  •  广开言路
    2021-01-07 15:55

    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.

    0 讨论(0)
提交回复
热议问题