用sqlserver里提供的函数
DATEDIFF(day,date1,date2)*24

解决方案 »

  1.   

     decHH:=strtoint(formatdatetime(time1,mm)-formatdatetime(time2,mm)) div 60;
     inthh:= strtoint(formatdatetime(time1,hh)-formatdatetime(time2,hh));
     your result:=inthh+decHH; 
      

  2.   

    如果两个日期都是TDatetime,简单地,
    (日期1-日期2)/(1/24)
    如果是字符串,用StrToDatetime尝试转换。
      

  3.   

    //for Delphi6 DateUtils.pas
    { Range query functions }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;
      

  4.   

    { 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;
      

  5.   

    //for Delphi5 加如下代码
    function SpanOfNowAndThen(const ANow, AThen: TDateTime): TDateTime;
    begin
      if ANow < AThen then
        Result := AThen - ANow
      else
        Result := ANow - AThen;
    end;function HourSpan(const ANow, AThen: TDateTime): Double;
    const
      HoursPerDay = 24;
    begin
      Result := HoursPerDay * SpanOfNowAndThen(ANow, AThen);
    end;
      

  6.   

    TDATETIME类型是浮点类型
    把时间变成TDATEIME类型
    再把两个浮点类型一减 呵呵成了:)
      

  7.   

    delphi中日期型用浮点类型表示,1表示1天,即24小时,两个日期相减后乘以24就是它们相差的小时数。sender的方法是对的。