DelphiBasics
EndOfADay
Function
Generate a TDateTime value set to the very end of a day DateUtils unit
1 function EndOfADay(const Year, Month, Day Word):TDateTime;
2 function EndOfADay (const Year, DayOfYear Word:TDateTime;
Description
The EndOfADay function generates a TDateTime value set to the given year, month and day with a time set to 1 milli-second before midnight.
 
Version 1
 
Allows the Month and Day to be specified separately. The month must be between 1 (January) and 12 (December). The day must be between 1 and 31, depending on the year and month.
 
Version 2
 
Allows the Month and Day to be specified as a DayOfYear instead.
Notes
WARNING there appears to be a bug in Delphi (as tested by the author using Delphi 7.0 Professional build 4.453), where the long syntax version incorrectly uses the EndOfAMonth routine to calculate the end of the day.

Errors in the parameter values gives EConvertError.
Related commands
EndOfAMonthGenerate a TDateTime value set to the very end of a month
 Download this web site as a Windows program.




 
Example code : Set the date to last msec of the 20th century - illustrates Delphi bug
var
  mydate : TDateTime;

begin
  myDate := EndOfADay(1999, 365);

  // Ensure that milli-seconds are shown
  LongTimeFormat := 'hh:mm:ss.zzz';
  ShowMessage('End of 1999 using short syntax = '+DateTimeToStr(myDate));

  myDate := EndOfADay(1999, 12, 31);

  // Ensure that milli-seconds are shown
  LongTimeFormat := 'hh:mm:ss.zzz';
  ShowMessage('End of 1999 using  long syntax = '+DateTimeToStr(myDate));
  ShowMessage('WARNING - The above value is incorrect');
end;
Show full unit code
  End of 1999 using short syntax = 31/12/1999 23:59:59.999
  End of 1999 using long syntax = 30/01/2000 23:59:59.999
  WARNING - The above value is incorrect
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page