怎样得到一个年月对应的起始日期呢?如: '200302'对应于'2003年02月01日至2003年02月28日'  , '200303'对应于'2003年03月01日至2003年03月31日'

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var year, month: integer;
        _date: TDate;
        s1, s2: string;
    begin
       year := StrToInt(copy('200303', 1, 4));
       month := StrToInt(copy('200303', 5, 2));   _date := encodeDate(year, month, 1);
       S1 := FormatDateTime('yyyy "年" mm "月" d "日"', _date );
       _date := encodeDate(year, month+1, 1) - 1;
       S2 := FormatDateTime('yyyy "年" mm "月" d "日"', _date );   showmessage(s1 + '至'+ s2);
    end;
      

  2.   

    >>怎样得到一个年月对应的起始日期
    起始肯定是 1 號了!
    終的呢, 可用 DaysInAMonth(2000, 2) 來得到!!