Sign in Join
FPDoc Onlineexperiment

SameDateTime function

In unit DateUtils

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

Declaration

pascal
function SameDateTime(const A: TDateTime; const B: TDateTime): Boolean

Arguments

A

First TDateTime value.

B

Second TDateTime value.

Function result

True if A and B have the same date and time parts, False if not.

Description

SameDateTime compares the date/time parts of two timestamps A and B and returns True if they are equal, False if they are not.

The function simply checks whether CompareDateTime returns zero.

See also

Example: ex101

pascal
Program Example101;

{ This program demonstrates the SameDateTime function }

Uses SysUtils,DateUtils;

Const
  Fmt = 'dddd dd mmmm yyyy hh:nn:ss.zzz';

Procedure Test(D1,D2 : TDateTime);

begin
  Write(FormatDateTime(Fmt,D1),' is the same datetime as ');
  Writeln(FormatDateTime(Fmt,D2),' : ',SameDateTime(D1,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.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.