Help & Manual authoring tool
Here go a couple of handy functions when working with dates

Getting the dates of the first and last day of the month of a given date

Copyright © 2000 Ernesto De Spirito

EurekaLog - Catch and log every exception!

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;
JfControls Library - for Delphi and C++ Builder
Copyright © 2000/2006 Ernesto De Spirito.   All rights reserved.