我写了一个函数function convert(date:string):string;
var
  i:integer;
  resu:string;
begin
  if trim(date)<>'' then
  begin
    resu:=copy(date,0,4);
    resu:=resu+'-';
    resu:=resu+copy(date,6,2);
    resu:=resu+'-';
    resu:=resu+copy(date,9,2);
    result:=resu;
  end;
end;你每次可以先调用一下这个函数,下面是调用示例:
procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(convert('2002.03.06'));
end;传出来的是类似2002-03-06的字符串,然后就好办了
你也可以在sql里面用date函数来比较两个字符型的日期的大小

解决方案 »

  1.   

    var
      dd: string;
    begin
      {dd将以“2002.05.10”的格式显示,具体格式可以改变}
      DateTimeToString(dd,'yyyy.mm.dd',Date);//yyyy.mm.dd为显示格式
    end;
    还可以用Format改变
      

  2.   

    我也编了一个函数:
      function Convert(S:String):TDate;
      begin
        while Pos('.',S)<> 0 do
          S[Pos('.',S)]:='-';
        Result:=StrToDate(S);
      end;
    S为从VFP表中得到的时间串,然后转化成日期变量。不过从VFP中得出的串一定要正确时间格式(符合VFP表的标准)
    与当前时间比较可以这样完成:
    var
      DateStr:String;
      TempDate:TDate;
    begin
      DateStr:=Table1.FieldByName('日期字段').AsString;
     TempDate:=Convert(DateStr);
      if Date>TempDate then//当前时间大于表内时间
       ……
      else//当前时间不大于表内时间
       ……
    end;
      

  3.   

    1 FormatDateTime('yyyy.mm.dd',date)
    2 不要你索引
    3 多次判断 字符是数字 格式如何