delphi 年月日自动加一减一函数,月加一,月减一
月份减一月情况:
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()));