begin
     dt1:=Formatdatetime('YYYYMMDD', Now);
     with dm.workrecord_Query do
     dm.workrecord_Query.Close;
     dm.workrecord_Query.SQL.Clear;
     dm.workrecord_Query.SQL.Add('select max(workrecordid) as maxno from workrecord where workrecordid like '''+dt1+'''');
     dm.workrecord_Query.open;
     if dm.workrecord_Query.fieldbyname('maxno').asstring ='' then
     begin
      delete(dt1,1,1);
      qt2:='2'+dt1+'001';
     end
     else
     begin
      qt1:=dm.workrecord_Query.FieldByName('maxno').asstring;
      delete(qt1,1,1);
      qn1:=strtoint(qt1)+1;
      qt2:=inttostr(qn1);
      insert('2',qt2,1);
     end;
      record_RzEdit.Text:=qt2;

解决方案 »

  1.   

    d   Displays the day as a number without a leading zero (1-31).   
    dd   Displays the day as a number with a leading zero (01-31).   
    ddd   Displays the day as an abbreviation (Sun-Sat) using the strings given by the ShortDayNames global variable.   
    dddd   Displays the day as a full name (Sunday-Saturday) using the strings given by the LongDayNames global variable.   
    ddddd   Displays the date using the format given by the ShortDateFormat global variable.   
    dddddd   Displays the date using the format given by the LongDateFormat global variable.   
    e   (Windows only) Displays the year in the current period/era as a number without a leading zero (Japanese, Korean and Taiwanese locales only).   
    ee   (Windows only) Displays the year in the current period/era as a number with a leading zero (Japanese, Korean and Taiwanese locales only).   
    g   (Windows only) Displays the period/era as an abbreviation (Japanese and Taiwanese locales only).   
    gg   (Windows only) Displays the period/era as a full name. (Japanese and Taiwanese locales only).   
    m   Displays the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.   
    mm   Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.   
    mmm   Displays the month as an abbreviation (Jan-Dec) using the strings given by the ShortMonthNames global variable.   
    mmmm   Displays the month as a full name (January-December) using the strings given by the LongMonthNames global variable.   
    yy   Displays the year as a two-digit number (00-99).   
    yyyy   Displays the year as a four-digit number (0000-9999).   
    h   Displays the hour without a leading zero (0-23).   
    hh   Displays the hour with a leading zero (00-23).   
    n   Displays the minute without a leading zero (0-59).   
    nn   Displays the minute with a leading zero (00-59).   
     dt1:=Formatdatetime('YYYYMMDD', Now); //哪有这样写的改成TimeNow:=FormatDateTime('yyyy-mm-dd hh:nn:ss', Now());
      

  2.   

    当然你这写成下面这样也行TimeNow:=FormatDateTime('yyyymmddhhnnss', Now());
      

  3.   

    这是我写的,我用了没有什么问题,你参考一下吧,呵呵  DecodeDate(Now,Year,Month,Day);
      t1:=inttostr(month);
      tnum:=month;
      if tnum<10 then begin                    //判断月份是否为个位数,加0补齐两位数
        t1:='0'+t1;
      end;
      t2:=inttostr(year);
      with dm.macidqhQuery1 do begin
        close;
        sql.Clear;
        sql.Add('select * from T_macidqh order by bdh asc');
        open;
      if dm.macidqhQuery1.IsEmpty then
      t:=t2+t1+'0001'                          //如记录为空,记录从1开始
      else
      Last;
      t:=dm.macidqhQuery1 .Fields[0].AsString;
      t3:=copy(t,5,2);                         //在NO中取两位数为月份
      if t1<>t3 then                           //判断月份,相同则累计,不同则重新计
         t:=t2+t1+'0001'
      else
        t:=inttostr(strtoint(t)+1);
      end;
      

  4.   

    dt1:=Formatdatetime('YYYYMMDD', Now);改为dt1:=Formatdatetime('YYYYMMDD%', Now);