var
 t1,t2:TDateTime;
 x : integer;
begin
  ...
  x := round(t2-t1);
end;

解决方案 »

  1.   

    在Delphi中可以直接相减在SQL中可用DATEDIFF()
      

  2.   

    //from DateUtils.pas for Delphi6
    { Range spanning functions }
    { YearSpan and MonthSpan are approximates, not exact but pretty darn close }
    function YearSpan(const ANow, AThen: TDateTime): Double;
    function MonthSpan(const ANow, AThen: TDateTime): Double;
    function WeekSpan(const ANow, AThen: TDateTime): Double;
    function DaySpan(const ANow, AThen: TDateTime): Double;
    function HourSpan(const ANow, AThen: TDateTime): Double;
    function MinuteSpan(const ANow, AThen: TDateTime): Double;
    function SecondSpan(const ANow, AThen: TDateTime): Double;
    function MilliSecondSpan(const ANow, AThen: TDateTime): Double;
      

  3.   

    TDateTime实际上是一个实数,
    而且差1就表示差一天!
      

  4.   

    function youranswer(yourdatetime1,yourdatetime2):integer;
    begin
    str1:=formatdatetime('yy-mm-dd',yourdatetime1);
    str2:=formatdatetime('yy-mm-dd',yourdatetime2);
    str1:=copy(str1,7,2);
    str2:=copy(str2,7,2);
    result:=strtoint(str2)-strtoint(str1);
    end;
      

  5.   


      2个DateTime类型的相加减就行了。  所得的结果就是你想要的。
      

  6.   

    var
      i:Double;
      i2:integer;
    begin
      i:=DateTimePicker1.Date-DateTimePicker2.date;
      showmessage(floattostr(i)); 
      i2:=strtoint(floattostr(i));