function DateToDateOfDayS(Date1,Date2:TDateTime):Integer;
begin
Result:= (DateTimeToTimeStamp(Date1).Date-DateTimeToTimeStamp(Date2).Date);
if Result<0 then Result:=-Result;
Result:=Result+1;
end;
//刚才是求天数,还可以求小时数,如下:
procedure TForm1.Button1Click(Sender: TObject);
var
temp:TDateDiff;
begin
temp:=GetDateDiff(dtl.DateTime,dtf.DateTime);
edit1.Text:=intToStr(temp.days*24+temp.hours);
end;
function GetDateDiff(const Date1,Date2:TDateTime):TDateDiff;
var Diff:TDateTime;
temp:TDateDiff;
begin
Diff:=abs(Date1-Date2);
temp.days:=Trunc(Diff);
Diff:=(Diff-temp.days)*24;
temp.hours:=trunc(Diff);
Diff:=(Diff-temp.hours)*60;
temp.minutes:=trunc(Diff);
Diff:=(Diff-temp.minutes)*60;
temp.seconds:=trunc(Diff);
Diff:=(Diff-temp.seconds)*1000;
temp.mseconds:=trunc(Diff);
Result:=temp;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
temp:TDateDiff;
begin
temp:=GetDateDiff(dtl.DateTime,dtf.DateTime);
edit1.Text:=intToStr(temp.days);
end;
procedure TForm1.Button1Click(Sender: TObject);
var n:integer;
begin
n:=daysbetween(DateTimePicker1.DateTime,DateTimePicker2.DateTime);
edit1.Text:=inttostr(n);
end;