delphi 当月的第一天, 当月的最后一天

时间:2022-03-03 08:36:08

//取当月的第一天
function TDealWithXML.FDOM(Date: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
Result := EncodeDate(Year, Month, 1);
end;

//取当月的最后一天
function TDealWithXML.LDOM(Date: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
if Month < 12 then inc(Month)
else begin Month := 1; inc(Year) end;
Result := EncodeDate(Year, Month, 1) - 1;
end;