Delphi access 时间和当前时间判断比较,出现错误,请高人指正,为感!
备注:Fields[1]、Fields[2]、Fields[3]字段分别是年、月、时间,且在access表中都是文本格式。procedure TForm9.Timer1Timer(Sender: TObject);
var
nowh,nowd,nowm,m,d,h :String;
nowh1,h1 :TTime;
nowd1,nowm1,m1,d1 :TDate;
begin
ADOQuery1.close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.add('select * from reminder');
ADOQuery1.Prepared;
ADOQuery1.Open;
while not ADOQuery1.Eof do
begin
  nowh:= FormatDateTime('hh:nn',now);
  nowd:= FormatDateTime('dd',now);
  nowm:= FormatDateTime('mm',now);
  m:= ADOQuery1.Fields[1].AsString;
  d:= ADOQuery1.Fields[2].AsString;
  h:= ADOQuery1.Fields[3].AsString;
  nowh1:= StrToTime(nowh);
  nowd1:= StrToTime(nowd);
  nowm1:= StrToTime(nowm);
  m1:= StrToTime(m);
  d1:= StrToTime(d);
  h1:= StrToTime(h);
  if nowh1 = h1 then
  begin
  showmessage('提醒1');
  end;
  if nowd1 + nowh1 = d1 + h1 then
  begin
  showmessage('提醒2');
  end;
  if nowm1 + nowd1 + nowh1 = m1 + d1 + h1 then
  begin
  showmessage('提醒3');
  end;  ADOQuery1.Next;
end;
end;

解决方案 »

  1.   

    用FormatDateTime转换成统一格式比较,像这样if FormatDateTime('hh:nn',Now)=FormatDateTime('hh:nn',ADOQuery1.Fields[1].AsDateTime) then
      

  2.   

    你这样换来换去容易把人搞晕。
    到底出了什么错误?
    我觉得不应该有ADOQuery1.Next;这句。
      

  3.   

    delphi中的日期时间是double类型的,所以用"="来比较,可能不会是你想象的结果可以从日期时间中分离出年、月、日,时、分、秒,再分别比较如果直接用TDatetime类型来比较,最好用范围比较,>=,<=