要自动生成诸如041215A001,041215A002,041215P001,041215P002,0411216A001,041216A002,041216P001,A代表上午。P代表下午,041215代表日期如何生成啊?

解决方案 »

  1.   

    function generate(aDate:TDateTime):STring;
    begin
      result := FormatDateTime('yymmdda/p',aDate);
    end;
      

  2.   

    showmessage(formatdatetime('yymmdd',now));
    至于上下午 无非是 判断时间是否比12:00大然后选A或P
    序号可以用SELECT MAX() WHERE COLUMN LIKE ‘041215A%’的方式得到
      

  3.   

    function TfrmSaleProduct.ConvertDateToStr(Value: TDateTime): String;
    var
      Y,M,D :Word;
      StrY,StrM,StrD:string;
    begin
      Decodedate(value,Y,M,D);
      StrY:=copy(IntToStr(Y),3,2);
      if M<10 then
        StrM:='0'+IntToStr(M)
      else
        STrM:=IntToStr(M);
      if D<10 then
        StrD:='0'+IntToStr(D)
      else
        StrD:=IntToStr(D);
      Result:=StrY+StrM+StrD;
    end;function TfrmSaleProduct.GetDocumentCode: string;
    var
      s:String[3];
      I:integer;
      Str:string;
    begin
      With quTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select isnull(max(SubString(DocumentCode,len(DocumentCode)-2,3)),'''')from SaleProductMX '
            +  ' where substring(convert(varchar,getdate(),112),3,8) =SubString(DocumentCode,1,6) ');
        sql.Add(str);
        open;
         if Length(Trim(Fields[0].AsString))>0 then
        begin
          S:=IntToStr(StrToInt(Fields[0].AsString)+1);
          for i:= Length(S) to 2 do
            S:='0'+ S;
          Result :=ConvertDateToStr(now)+'A'+S;
        end
        else
          Result := ConvertDateToStr(now)+'A'+'001';
      end;
    end;
    请修改修改
      

  4.   

    use dateutils
    if hourof(now)<12 then
    showmessage(FormatDateTime('yymmddA',Date))
    else
    showmessage(FormatDateTime('yymmddP',Date));