//返回最近几个年月
procedure TForm1.Button1Click(Sender: TObject);
var
num,mon,i:integer;
mm,yearMonth:string;
begin //返回最近几个年月
memo1.Clear;
yearmonth:=formatDateTime('yyyymm',date) ;
mon:=strToInt(copy(yearMonth,5,7));
num:=3;
for i:=0 to num-1 do
begin
if mon>i then
begin
mm:=intTostr(mon-i ) ;
if StrToInt(mm)<10 then
begin
mm:='0'+ mm ;
end
else
begin
mm:= mm ;
end;
memo1.Lines.Add(copy(yearMonth,1,4)+ mm ) ;
end
else
if mon<=i then
begin
mm:=intToStr(12+ mon -i);
if StrToInt(mm)<10 then
begin
mm:='0'+ mm ;
end
else
begin
mm:= mm ;
end;
memo1.Lines.Add(intTostr(strToInt(copy(yearMonth,1,4))-1)+ mm ) ;
end;
end;
end;