PhysiologyWeb Logo  Search
Share on Facebook Share on Twitter Share on LinkedIn Share on Pinterest Email Copy URL
PhysiologyWeb Loading...

Memorial Day - Last Monday in May
Here is a simple Delphi function that takes a year as its input and returns the date for Memorial Day (last Monday in May), a day that is meant to honor and mourn all U.S. military personnel who died while serving in the United States Armed Forces. For additional Delphi code to return key dates, see Delphi Code To Return Holidays, Observances, Celebrations, Historical, and Other Key Dates.
function MemorialDay(TargetYear: Integer): TDate;
var
MondayCount: Integer;
TargetDate: TDate;
begin
MemorialDay := 0;

MondayCount := 0;

TargetDate := 0;

TargetDate := StrToDate('5/31/'+IntToStr(TargetYear));
MondayCount := 0;
If DayOfTheWeek(TargetDate) = 1 then MondayCount := 1; //1 = Monday
If MondayCount = 0 then
begin
repeat
TargetDate := TargetDate - 1;
If DayOfTheWeek(TargetDate) = 1 then MondayCount := MondayCount + 1;
until MondayCount = 1;
end;

MemorialDay := TargetDate;
end;
The procedure below uses the function shown above to retrieve Labor Day for a range of years. The FormatDateTime function can be used to format the date in any way desired.
procedure TForm1.Button1Click(Sender: TObject);
var
Year: Integer;
begin
For Year := 2000 to 2100 do
begin
Memo1.Lines.Add(FormatDateTime('dddd, mmmm d, yyyy', MemorialDay(Year)));
end;
end;






Posted: Saturday, December 7, 2024