有两个时间控件d1,d2
我想d2-d1(两个时间控件)<=5分钟时
就是
if d2.datetime-d1.datetime<=5分钟 then
...
要怎么实现??

解决方案 »

  1.   

    datediff();
    参数是两个时间还有时间间隔的单位精度 如秒,分钟什么的
      

  2.   

    function ToTime(DateTime:TDateTime;day,hour,minute,second:{加减量}integer):TDateTime;{给出一个具体时间,减去天数或小时、分钟、秒钟,即得到新时间}varhh,mm,ss,ms:word;hx,mx,sx:integer; {时间中间值}dt:TDate;begindt :=DateTime;DecodeTime(DateTime,hh,mm,ss,ms);hx:=hh;mx:=mm;sx:=ss;{秒}sx:=sx+second;if sx<0 thenbeginminute :=minute + (sx div 60)-1;sx :=60 +(sx mod 60);endelse if sx>=60 thenbeginminute :=minute+(sx div 60);sx :=sx mod 60;end;{分}mx :=mx+minute;if mx<0 thenbeginhour :=hour+(mx div 60)-1;mx :=60+(mx mod 60);endelse if mx>=24 thenbeginhour :=hour+(mx div 60);mx :=mx mod 60;end;{时}hx :=hx+hour;if hx<0 thenbeginday :=day+(hx div 24)-1;hx :=24+(hx mod 24);endelse if hx>=24 thenbeginday :=day+(hx div 24);hx :=hx mod 24;end;{天}dt :=dt+day;DateTime :=StrToDateTime(DateToStr(dt)+' '+IntToStr(hx)+':'+IntToStr(mx)+':'+IntToStr(sx)+':');Result :=DateTime;end;这是尚在编制中的源码,求两个时间差:天数、小时、分钟等。各位有兴趣,可自己编个函数!procedure TForm1.Button3Click(Sender: TObject);varday,hour,minute,second,h,m,s:integer;hh1,mm1,ss1,ms1,hh2,mm2,ss2,ms2:word;dt1,dt2:TDateTime;begin{两个时间差}dt1 :=StrToDateTime(Edit1.text);dt2 :=StrToDatetime(Edit2.text);DecodeTime(dt1,hh1,mm1,ss1,ms1);DecodeTime(dt2,hh2,mm2,ss2,ms2);day:=dt1-dt2; file://就日期不能相差,怎么办?h:=hh1;m:=mm1;s:=ss1;if s<ss2 thenbeginm:=m-1;s:=s+60;end;second :=s-ss2;if m<mm2 thenbeginh:=h-1;m:=m+60;end;minute :=m-mm2;if h<hh2 thenbeginday :=day-1;h:=h+24;end;hour :=h-hh2;edit3.Text :='相差'+IntToStr(day)+'天'+IntToStr(Hour)+'小时'+IntToStr(minute)+'分'+IntToStr(Second)+'秒';end;
      

  3.   

    TDateTime d1,d2;
    ...
    if (d2 - d1 <= 5.0 * 60 / (24.0 * 3600.0))
        ...
    else
        ...