Comparing Time Values

霸气de小男生 提交于 2019-12-09 01:54:26

问题


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 said in "Bold Brackets" (see below)

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). GreaterThanValue if A occurs later in the day than B (even if A occurs on an earlier day than B).


回答1:


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.



来源:https://stackoverflow.com/questions/23990987/comparing-time-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!