bdn.borland.com

Article #27805: How to get the date of the last day in the current month.

QUESTION:

How do can I find out the date, of the last day in the current month?

ANSWER:

Drop a button on a form and add the code snippit below. The show message dialog will reveal the date.


function LastDayCurrMon: TDate;
var
  y, m, d: word;
begin
  decodedate(now, y, m, d);
  m := m + 1;
  if m > 12 then
  begin
    y := y + 1;
    m := 1;
  end;
  result := encodedate(y, m, 1) - 1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DateToStr(LastDayCurrMon));
end;

Last Modified: 09-OCT-01