[Overview][Constants][Procedures and functions] |
Compare 2 dates, disregarding the time of day
Source position: dateutil.inc line 352
function CompareDate( |
const A: TDateTime; |
const B: TDateTime |
A |
|
First date to compare |
B |
|
Second date to compare |
A negative number if date Ais before B, zero if they are equal, or positive if Ais after B.
CompareDatecompares the date parts of two timestamps Aand Band returns the following results:
|
Compares two times of the day, disregarding the date part. |
|
|
Compare 2 dates, taking into account the time of day |
|
|
Check whether two TDateTimevalues have the same date part. |
|
|
Check whether two TDateTimevalues have the same time part. |
|
|
Check whether two TDateTimevalues have the same date and time parts. |
Program Example99; { This program demonstrates the CompareDate function } Uses SysUtils,DateUtils; Const Fmt = 'dddd dd mmmm yyyy'; Procedure Test(D1,D2 : TDateTime); Var Cmp : Integer; begin Write(FormatDateTime(Fmt,D1),' is '); Cmp:=CompareDate(D1,D2); If Cmp<0 then write('earlier than ') else if Cmp>0 then Write('later than ') else Write('equal to '); Writeln(FormatDateTime(Fmt,D2)); end; Var D,N : TDateTime; Begin D:=Today; N:=Now; Test(D,D); Test(N,N); Test(D+1,D); Test(D-1,D); Test(D+OneSecond,D); Test(D-OneSecond,D); Test(N+OneSecond,N); Test(N-OneSecond,N); End.