請舉例說明

解决方案 »

  1.   

    if FormatDateTime('hh,nn,ss,zzz',时间1)>=FormatDateTime('hh,nn,ss,zzz',时间2) then......
      

  2.   

    时间实质上是浮点数,年月日是整数部分,时分秒是小数部分。
    比較時間大小:
     (1)判断带有时分秒的时间,直接用 
             iFloat:= dateTime1-dateTime2;
             if iFloat=0 then showMessage('相等');
             if iFloat>0 then showMessage('dateTime1 大于 dateTime2');
             if iFloat<0 then showMessage('dateTime1 小于 dateTime2');
     (2)只判断年月日的时间
        var Date1,Date2:TDateTime;  sDate1,sDate2:string;
        ...
        sDate1:=formatDateTime('yyyy-mm-dd',dateTime1);  //因为dateTime1,dateTime2
        sDate2:=formatDateTime('yyyy-mm-dd',dateTime2);  //可能包含时分秒(小数部分)
        Date1:=strToDateTime(sDate1);
        Date2:=strToDateTime(sDate2);
        iInt:=Date1-dDate2;
        if ....... 同上
      

  3.   

    (2)只判断年月日的时间
    trunc(datetime1)-trunc(datetime2)  //trunc取整
      

  4.   

    谢谢 netwolfds(晓竹) ,我怎么没想到trunc取整呢,应该这样优化
      

  5.   

    delphi中的时间其实就是浮点数。小虾无招支的招很好,如果光比较大小,不取差值的话,可以用晓竹的办法。
      

  6.   

    时间类型和时间类型就可以直接比较!
    不是时间类型就转化成时间类型然后比较
    有问题请发信息到我的E-mail:[email protected]
      

  7.   

    if datetimepicker1.date>datetimepicker2.date then showmessage('>');
      

  8.   

    TFileTime \ TDateTime 比較
      

  9.   

    把TFILEDATE转成TDATETIME后用 >,<,=进行比较