可以将要查的日期值用引号括起来,如:
Select * from TableName where DateFileName>'2002-01-20 10:00:00'

解决方案 »

  1.   

      with query1 do
      begin
        close;sql.clear;
        sql.add('select * from tiku where enterdate='+''''+edit3.Text+'''');
        open;
      end;
    不行啊,出错啊
       edit3里填2001-01-01 00:00:00
    报错:Type Mismatch in expression
      

  2.   

    'select * from tiku where enterdate=''''+edit3.Text+''''
      

  3.   

    sql.add('select * from tiku where enterdate='+''''+edit3.Text+'''');
    改这样试:
    var ddate:DataTime;
    txt:string;
    ddate:=strtodatetime(edit3.Text);
    txt:='select * from tiku where enterdate='''+FormatDateTime('yyyy-mm-dd hh:mm:ss',ddate)+'''';
    sql.add(txt)
      

  4.   

    这与数据库有关,需在注册表里改DATEFORMAT的格式。
    为'YYYY-MM-DD HH24:MI:SS'
      

  5.   

    这与数据库有关,需在注册表里改DATEFORMAT的格式。
    为'YYYY-MM-DD HH24:MI:SS'
      

  6.   

    paradox
    'mm/dd/yyyy hh:nn:ss'access
    #yyyy-mm-dd hh:nn:ss'sql server
    'yyyy-mm-dd hh:nn:ss'
      

  7.   

    begin
      Query1.Close;
      Query1.SQL.Text := Format(
    'select *'#13#10 +
    'from tiku'#13#10
    'where enterdate=''%s'''#13#10,
        [FormatDateTime('mm/dd/yyyy hh:nn:ss', StrToDateTime(Edit3.Text))]);
      Query1.Open;
    end;
      

  8.   

    select * from syd where srq>to_date('2001/01/01','yyyy/mm/dd')
      

  9.   

    用between...and...,但有时候好象不行
      

  10.   

      谢谢大家的答案,虽然都没答全对,但在大家的提示下,我研究出来,我把我研究出来的结果写出来和大家分享,我用的是paradox数据库,用sql查询日期型字段应该用
      select * from tiku where enterdate>'11/10/2001 12:02:25:20'
    注意要加上毫秒
      with query1 do
      begin
        close;sql.clear;
        sql.add('select * from tiku where enterdate>'+''''+edit3.text+'''');
        open;
      end;
    其中edit3.text填01/01/2001 12:12:12:12 这样就可以了
    值得一提的是不能用FormartDateTime这个函数
      FormartDateTime('mm/dd/yyyy hh:nn:ss',strtodatetime(edit3.text))
    这样'/'会莫名其妙的被换成'-'
    还有strtodatetime('01-01-2000 12:02:01:00')
    strtodatetime('01-01-2000 12:02:01')
    strtodatetime('01/01/2000 12:02:01')
    strtodatetime('2000-01-01 12:02:01')
    这些统统错
    strtodatetime('2000-01-01')
    这样对
    所以如果edit3.text填2001-01-01想查询用下面的代码:
    procedure TForm1.Button2Click(Sender: TObject);
    var tempsql:string;ddate:TDateTime;yyyy,mm,dd,hh,nn,ss,ms:word;
    begin
      ddate:=strtodatetime(edit3.text);
      decodedate(ddate,yyyy,mm,dd);
      decodetime(ddate,hh,nn,ss,ms);
      tempsql:='';
      tempsql:=inttostr(mm)+'/'+inttostr(dd)+'/'+inttostr(yyyy)+' '
                 +inttostr(hh)+':'+inttostr(nn)+':'+inttostr(ss)+':'+inttostr(ms);
      with query1 do
      begin
        close;sql.clear;
        sql.Add('select * from tiku where enterdate='+''''+tempsql+'''');
        open;
      end;
    end;
    其中细节也不太清楚,这些是试出来的,看大家有什么意见  
      

  11.   

    FormatDateTime('mm"/"dd"/"yyyy hh:nn:ss',strtodatetime(edit3.text))
    //                ~~   ~~加个"解决
      

  12.   

    sql.add('select * from tiku where enterdate=#'+ date +'#'
      

  13.   

    如果是ACCESS,这样写:
    select * from tablename where mydate=#2001-2-2#如果是SQL SERVER,这样写:
    select * from tablename where mydate='2001-2-2'
      

  14.   

    SELECT gl_no
    FROM gl
    WHERE gl_status='检修' and convert(char(8),gl_date,112)=convert(char(8),getdate(),112)
    刚才一个朋友告诉我的,已经通过验证了。
      

  15.   

    SQL自己说,查询日期最好是用Like来做.
      

  16.   

    如果是查询Access数据库要用 # 括起来
    如果是SQL Server就用 ' 括起来
      

  17.   

    select * from 表名 where 列名>to_date('2001/01/01','yyyy/mm/dd')
      

  18.   

    我有一个SQL查询的示例 请给我电子邮件,[email protected]