要计算两个日期之间相隔的天数,应该怎样写代码?
如下这样写肯定是不行的吧
  var Date1,Date2:TDateTime;
  begin
    n:=Date-Date2;
  end;

解决方案 »

  1.   

    var n:integer;n:=round(date-date2);
      

  2.   

    不行呀,编译时提示错误:
    Incompatible types:'integer' and 'Extended';
      

  3.   

    TO:lgwangshu(我思...故我在!) 
    按你的方法,编译时不出错,
    但是运行到n:=round(date-date2);这一句时就死机了
      

  4.   

    Num_MonthDay := Trunc(Now) - Trunc(DateTimePicker_ZNJ.Date);
    我用的就是它,没问题的
      

  5.   

    还是用delphi的函数吧
    function DaysBetween(const ANow, AThen: TDateTime): Integer;
    其中参数均为日期型。返回的值就是两个日期的相差天数。
    绝对不会出错!
    见delphi的帮助吧,还有很多类似功能的函数(都是dayXXXX)
      

  6.   

    TO:TO:lgwangshu(我思...故我在!) 
    呵呵,你的是对的,给分了