我的数据表T1内有字段chno  char(12)  
内有数据
         chno        dateno   
        031108       2003-11-08
        031101       2003-11-01
        031110       2003-11-00
        031111       2003-11-11
        031111       2003-11-11
我要一次性把它转成日期型的,格式:2003-11-08       请各位帮忙分别用DELPHI循环语句一次性把我所有的数据从表t1内的以chno char(12)转到另一个字段dateno  datetime内

解决方案 »

  1.   

    var
      I:integer;
      astr:string;
    begin
    For I:=0 to table.recoredcount-1 do
    begin
      astr:=fieldbyname(chno).asstring;
      fieldbyname('dateno').value:=strtodate('20'+astr[1]+astr[2]+'-'+astr[3]+astr[4]+'-'+astr[5]+astr[6]);
      post;
      next;
    end;
    end;
      

  2.   

    function chno_dateno(value:string): tdatetime;
     var
       bl: Tdatetime;
       fyear, fmonth, fday: word;
    begin
       fyear:=strtoint('20'+copy(value,1,2));
       fmonth:=strtoint(copy(value,3,2));
       fday:=strtoint(copy(value,5,2));
       bl:=encodedate(fyear,fmonth,fday);
       result:=bl;
    end;
      

  3.   

    select chno,convert(datetime,substring(chno,3,2)+'-'+substring(chno,5,2))+'-'+substring(chno,1,2) as dateno from table1//注意:‘月-日-年’