我想计算两个日期相差几天,并且返回的是整数,请教如何实现:
 a:integer;
 time:=adoquery1.FieldByName('归还时间').asdatetime;
 a:=datetoint(date()-time);
可不行,没有datetoint此函数,真是笑死,麻烦大家指点下

解决方案 »

  1.   

    a:=trunc(date()-time);或者Unit 
    DateUtils [Delphi] function DaysBetween(const ANow: TDateTime; const AThen: TDateTime): Integer;
      

  2.   

    lz 应该先看下 delphi 的 时间定义In Delphi, TDateTime is a type that maps to a Double. In C++, the TDateTime class corresponds to the Delphi TDateTime type. 
    The integral part of a Delphi TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of the TDateTime value is fraction of a 24 hour day that has elapsed
      

  3.   

    TDateTime = double; 属于 IEEE 标准整数部分是从 1899-12-31 为 0, 起计的总计天数
    小数部分是时间, 从 0 点计 1ms 的总计
      

  4.   

    向vividw,comanche大哥学习!!
    按照delphi的定义,delphi中处理日期型是按照double处理的,整数部分是天数,小数部分表示时分秒,所以如果计算两日期相差几天,直接相减即可然后trunc,并且相减后数值只能是数值型的,怎么可能是date呢,呵呵
    如果计算一天两个时间点相差几分钟时,可以相减后乘以24*60后再trunc即可
      

  5.   

    提示:TDateTime实际是dword类型的,可以直接加减