利用分隔符‘-’。先用pos找到他的位置,再用copy把相应的子串拷贝出来

解决方案 »

  1.   

    用Pos函数,或者更专业的是WrapText,自己查帮助
      

  2.   

    或者用下面的办法:
    str := '1996-8-9';
    dat := StrToDate(Str);yy  := formatDateTime('yyyy',dat);
    mm  := formatDateTime('mm',dat);
    dd  := formatDateTime('dd',dat);
      

  3.   

    上面这种办法比较保险,可避免各计算机的时间格式设置不一样当然运行结果yy=1998
     mm=8
      dd=9
      

  4.   

    Copy('1996-8-9',1,4)
    Copy('1996-8-9',6,1)
    Copy('1996-8-9',8,1)
      

  5.   

    str := '1996-8-9';
    dat := StrToDate(Str);
    DecodeDate(dat,yy,mm,dd);
    哈哈哈哈,^_^
      

  6.   

    我比较同意dbpower的方法,即:
      str := '1996-8-9';
      dat := StrToDate(Str);  yy  := formatDateTime('yyyy',dat);
      mm  := formatDateTime('mm',dat);
      dd  := formatDateTime('dd',dat);
    因为在delphi中是尽可能避免使用copy函数的,他牵涉到内存地址分配的问题,效率不高。
    上述意见,仅供参考。
      

  7.   

    var
     present:TDateTime;
     Year,Month,Day:word;
     str,stryear,strmonth,strday:string;
    begin
     Present:=strtodate(str);
     Decodedata(Present,Year,Month,Day);
     stryear:=intTostr(Year);
     strmonth:=intTostr(Month);
     strday:=inttostr(Day);