如果我没记错的话,Delphi中两个日期型的变量相减就可得出天数。要是不行的话,我建议你可以先分别把年、月、日都减出来,再将年、月换算成天数求和即可。提示:可用截取字符串的方式分离年、月、日。还要注意2月份的天数。

解决方案 »

  1.   

    EncodeDate(2000,1,26)-EncodeDate(1999,3,19)
      

  2.   

    delphi中两日期相减,得出的整数部分就是相差的天数。
      

  3.   

    呵呵,给你一个最最原始的方法,是我在学Pascal时编的程序。(有减)
    //看能不能捞点分,嘿嘿program datecount;
     var
       y1,m1,d1,y2,m2,d2,t:integer;
       c:real;
     function ck(y:integer):boolean;  {判断是否润年}
      begin
        ck:=(y mod 4=0) and (y mod 100<>0) or (y mod 400=0);
      end;
     function gd(y,m:integer):integer;  {求某年某月有多少天}
      begin
        case m of 
         4,6,9,11:gd:=30;
         2       :if ck(y) then gd:=29
                           else gd:=28;
         else    :gd:=31;
      end;
     begin
       write("Please input the little date:year,month,date:");
       readln(y1,m1,d1);
       write("Please input the large date:year,month,date:");
       readln(y2,m2,d2);
       t:=y2-y1-1;
       if t>=0
        then
         begin
           c:=365*t;
           for t:=y1+1 to y2-1 do
             if ck(t) then c:=c+1;
           for t:=m1+1 to 12 do
             c:=c+gd(y1,t);
           c:=c+gd(y1,m1)-d1;
           for t:=1 to m2-1 do
             c:=c+gd(t);
           c:=c+d2;
         end  {then}
        else
         begin
           if m1=m2 then c:=d2-d1
           else
            begin
              c:=gd(y1,m1)-d1;
              for t:=m1+1 to m2-1 do
                c:=c+gd(y1,t);
              c:=c+d2;
            end;
         end;{else}
       writeln('The result is:',c:10:0);
     end.
      

  4.   

    用大日期减小日期得出的整数部分就是相差天数了。
    例:
    Function TForm1.Date_H(date1,date2:tdate):integer;
    begin
      result:=trunc(date2-date1);
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    //相差天数
    label1.caption:=inttostr(date_H(strtodate(edit1.text),strtodate(edit2.text)));
    end;