下面的代码应该输出1吧?可是输出了0!
help里说
HoursBetween reports the difference between 9:00 AM and 9:59:59 AM as 0 because the difference is one second short of an entire hour.
可是好像只对起始时间非0的有效。uses DateUtils;procedure TForm1.Button1Click(Sender: TObject);
var
  dtStart, dtEnd : TDateTime;
  nowDate, LastDate : TDate;
  ftMax, ftMin : double;
begin
  dtStart := IncHour( DateOf(now), StrToInt('0') );
  dtEnd := IncHour( DateOf(now), StrToInt('1') );
  ShowMessage( IntToStr(Hoursbetween(dtStart,dtEnd) ))
end;

解决方案 »

  1.   

    Thus, HoursBetween reports the difference between 9:00 AM and 9:59:59 AM as 0 because the difference is one second short of an entire hour.
      

  2.   

    关键问题出在Trunc与浮点数。
      

  3.   

    ShowMessage( IntToStr(Hoursbetween(strtodatetime('2005-7-22 9:00:00'),strtodatetime('2005-7-22 9:59:59'))))如果这样就可以返回1。晕了!
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      dtStart, dtEnd : TDateTime;
    begin
      dtStart := now;//IncHour( now, StrToInt('0') );
      dtEnd := now+strtotime('2:00:00');//IncHour( now, StrToInt('1') );
      showmessage(datetimetostr(dtstart));
      showmessage(datetimetostr(dtend));  ShowMessage( IntToStr(Hoursbetween(dtStart,dtEnd)))
    end;你再试试这个,返回2,又对了,我更晕。差一天返回24也对了,就差1小时返回的值不对。
      

  5.   

    唉,终于测试出来了,必须超过1小时才返回1呢,正好=1小时返回0;
    procedure TForm1.Button1Click(Sender: TObject);
    var
      dtStart, dtEnd : TDateTime;
    begin
      dtStart := now;//IncHour( now, StrToInt('0') );
      dtEnd := now+strtotime('1:00:01');//IncHour( now, StrToInt('1') );
      showmessage(datetimetostr(dtstart));
      showmessage(datetimetostr(dtend));  ShowMessage( IntToStr(Hoursbetween(dtStart,dtEnd)))
    end;