adsMain.Active := false;
  adsMain.CommandText := 'select * from server_main where if_settle = ''Y'' and finish_time >= #'
      +FormatDateTime('yyyy-mm-dd',dtpStart.Date)+' '+formatdatetime('hh:mm',dtptStart.DateTime)+'# and finish_time <= #'
      +FormatDateTime('yyyy-mm-dd',dtpEnd.Date)+' '+formatdatetime('hh:mm',dtptEnd.DateTime)+'# order by finish_time';
  adsMain.Active := true;后来我把小时和分去掉就可以了,如下
  adsMain.CommandText := 'select * from server_main where if_settle = ''Y'' and finish_time >= #'
      +FormatDateTime('yyyy-mm-dd',dtpStart.Date)+'# and finish_time <= #'
      +FormatDateTime('yyyy-mm-dd',dtpEnd.Date)+'# order by finish_time';

解决方案 »

  1.   

    用参数传递吧, 例如ADOQuery中
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from server_main  where if_settle between :timebegin and :timeend');
        Parameters.ParamByName('timebegin').Value := dtpStart.Date;
        Parameters.ParamByName('timeend').Value := dtpEnd.Date;
        Open;
      end;
    end;
      

  2.   

    FormatDateTime('yyyy-mm-dd hh:mm:ss',dtpStart.Date)
      

  3.   

    正确就好,带上小时和分的确有时候回出现一些奇怪的问题比如我想查 2004-3-19 好的记录可能就要写成 (AField => #2004-3-18#) and (AField <= #2004-3-20#)
      

  4.   

    最好的办法是用
    Parameters.ParamByName('timebegin').Value := dtpStart.Date;
        Parameters.ParamByName('timeend').Value := dtpEnd.Date;
      

  5.   

    where (Format(LIST_DATE,''yyyy-mm'')= Format(now,''yyyy-mm''))
      

  6.   

    试试把(m->n)
    formatdatetime('hh:mm',dtptStart.DateTime)
    改成:
    formatdatetime('hh:nn',dtptStart.DateTime)
      

  7.   

    对小时和分秒的支持,在access中不好的,如果没有特别的需要就不要加了