+ -
当前位置:首页 → 问答吧 → 日期比较问题 access

日期比较问题 access

时间:2011-12-13

来源:互联网

procedure TForm2.Button8Click(Sender: TObject);
var
str1,str2:string;

begin
  with adoquery2 do
  begin
  str1:=datetimetostr(DateTimePicker3.datetime);
  str2:=datetimetostr(DateTimePicker4.datetime);
  if ComboBox4.Text='' then
  begin
  close;
  sql.Clear;
  sql.Add('select * from sj where yh='''+yhs+''' and date1>='''+str1+''' and date1<='''+str2+'''') ;


  open;
  end
  else
  begin
  if ComboBox3.text='' then
  begin
  close;
  sql.Clear;
  sql.Add('select * from sj where date1<=:'''+str1+''' and date1>=:'''+str2+''' and zc='''+ComboBox4.text+''' and yh='''+yhs+''' ') ;
  open;
  end
  else
  begin
  close;
  sql.Clear;
  sql.Add('select * from sj where date1<=:'''+str1+''' and date1>=:'''+str2+''') and zc='''+ComboBox4.text+''' and ly='''+ComboBox3.text+''' and yh='''+yhs+''' ') ;
  open;
  end;
  end;
  end;
end;

作者: w187037   发布时间: 2011-12-13

你这不是日期比较实际上是字符串比较,正确的方式是在access里把字符串转为日期格式进行大于小于的比较
可以用cast

作者: funxu   发布时间: 2011-12-13