CompareTime
Compares two times of the day, disregarding the date part.
Declaration
Source position: dateutil.inc line 363
function CompareTime(const A: TDateTime; const B: TDateTime)
: TValueRelationship;
Description
CompareTime compares the time parts of two timestamps A and B and returns the following results:
- < 0
- if the time part of A is earlier than the time part of B.
- 0
- if A and B have the same time part (dates may differ) .
- > 0
- if the time part of A is later than the time part of B.
See also
Name | Description |
---|---|
CompareDate | Compare 2 dates, disregarding the time of day |
CompareDateTime | Compare 2 dates, taking into account the time of day |
SameDate | Check whether two TDateTime values have the same date part. |
SameDateTime | Check whether two TDateTime values have the same date and time parts. |
SameTime | Check whether two TDateTime values have the same time part. |
Example
Program Example100;
{ This program demonstrates the CompareTime function }
Uses SysUtils,DateUtils;
Const
Fmt = 'dddd dd mmmm yyyy hh:nn:ss.zzz';
Procedure Test(D1,D2 : TDateTime);
Var
Cmp : Integer;
begin
Write(FormatDateTime(Fmt,D1),' has ');
Cmp:=CompareDateTime(D1,D2);
If Cmp<0 then
write('earlier time than ')
else if Cmp>0 then
Write('later time than ')
else
Write('equal time with ');
Writeln(FormatDateTime(Fmt,D2));
end;
Var
D,N : TDateTime;
Begin
D:=Today;
N:=Now;
Test(D,D);
Test(N,N);
Test(N+1,N);
Test(N-1,N);
Test(N+OneSecond,N);
Test(N-OneSecond,N);
End.