月份减一月情况:
function GetLastMonth(ADate : TDateTime) : TDateTime;
var
dwYear, dwMonth, dwDay : Word;
begin
Result := ADate;
Try
DeCodeDate(ADate, dwYear, dwMonth, dwDay);
Result := EncodeDate(dwYear, dwMonth, 1) - 1;
except
end;
end
月份增加一月情况:
function TForm1.GetLastMonth(ADate: TDateTime): TDateTime;
var
dwYear, dwMonth, dwDay : Word;
begin
Result := ADate;
Try
DeCodeDate(ADate, dwYear, dwMonth, dwDay);
if dwMonth=12 then
begin
Result := EncodeDate(dwYear+1, 1, 1);
end
else
Result := EncodeDate(dwYear, dwMonth+1, 1);
except
end;
end;
调用:
Edit1.Text:=DateTimeToStr(GetLastMonth(Date()));
时间: 2024-10-29 19:10:55