delphi xe10.2 统计(计算)日期

unit Unit1;

interface

uses
   System.SysUtils,
    Vcl.Forms,  Vcl.StdCtrls, Vcl.ComCtrls,  Vcl.Controls, System.Classes;

type
  TForm1 = class(TForm)
    Button1: TButton;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
 uses System.DateUtils;//调用单元文件  必须D
procedure TForm1.Button1Click(Sender: TObject);
begin
    if DateTimePicker1.Date <= DateTimePicker2.Date then
     edit1.Text:=inttostr(System.DateUtils.DaysBetween(DateTimePicker1.Date,
                                     DateTimePicker2.Date));

end;

end.

{

function YearsBetween(const ANow, AThen: TDateTime): Integer;
function MonthsBetween(const ANow, AThen: TDateTime): Integer;
function WeeksBetween(const ANow, AThen: TDateTime): Integer;
function DaysBetween(const ANow, AThen: TDateTime): Integer;
function HoursBetween(const ANow, AThen: TDateTime): Int64;
function MinutesBetween(const ANow, AThen: TDateTime): Int64;
function SecondsBetween(const ANow, AThen: TDateTime): Int64;
function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;
}

效果如下

 delphi xe10.2 统计(计算)日期