Getting the dates of the first and last day of the month of a given date
Copyright © 2000 Ernesto De Spirito
![]() |
FDOM and LDOM
FDOM returns the date that corresponds to the first day of the same month as
the date passed as parameter, while LDOM returns the date that corresponds to
the last day of the month (subtracting 1 from the date that corresponds to
the first day of the next month).
uses SysUtils;
function FDOM(Date: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
Result := EncodeDate(Year, Month, 1);
end;
function 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;
Result := EncodeDate(Year, Month,
MonthDays[IsLeapYear(Year), Month]);
end;
Sample call
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(DateToStr(FDOM(Now)));
ShowMessage(DateToStr(LDOM(Now)));
end;
![]() |



