if FormatDateTime('hh,nn,ss,zzz',时间1)>=FormatDateTime('hh,nn,ss,zzz',时间2) then......
时间实质上是浮点数,年月日是整数部分,时分秒是小数部分。 比較時間大小: (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 ....... 同上
比較時間大小:
(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 ....... 同上
trunc(datetime1)-trunc(datetime2) //trunc取整
不是时间类型就转化成时间类型然后比较
有问题请发信息到我的E-mail:[email protected]