ObjectPascal
EndOfAMonth
Function
Generate a TDateTime value set to the very end of a month DateUtils unit
 function EndOfAMonth ( const Year, Month : Word ) : TDateTime;
Description
The EndOfAMonth function generates a TDateTime value set to the given Year and Month with the day set to the last of the month, and the time set to 1 milli-second before midnight.
 
The Year value must be between 0 and 9999.
 
The Month value must be between 1 (January) and 12 (December).
Notes
Errors in the parameter values gives EConvertError.
Related commands
EndOfADay Generate a TDateTime value set to the very end of a day
 
Example code : Set the date to the last millisecond of February 2000, a leap month
var
  mydate : TDateTime;

begin
  myDate := EndOfAMonth(2000, 2);

  // Ensure that milli-seconds are shown
  LongTimeFormat := 'hh:mm:ss.zzz';
  WriteLn('End of February 2000 = '+DateTimeToStr(myDate));
end;
Show full unit code
   End of February 2000 = 29/02/2000 23:59:59.999