[Overview][Constants][Procedures and functions][Index] Reference for unit 'dateutils' (#rtl)

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;

Arguments

A

  

First time to compare

B

  

Second time to compare

Function result

A negative number if A is before B, zero if they are equal, or positive A is later than B.

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

CompareDateTime

  

Compare 2 dates, taking into account the time of day

CompareDate

  

Compare 2 dates, disregarding the time of day

SameDate

  

Check whether two TDateTime values have the same date part.

SameTime

  

Check whether two TDateTime values have the same time part.

SameDateTime

  

Check whether two TDateTime values have the same date and time parts.

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.

Documentation generated on: Nov 16 2015