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

Presidents' Day - Washington's Birthday - Third Monday in February
Here is a simple Delphi function that takes a year as its input and returns the date for Presidents' Day (third Monday in February), a day that is meant to celebrate all former US presidents. Presidents' Day is officially known as Washington's Birthday. George Washington, the first president of the United States of America, was born on February 22, 1732. For additional Delphi code to return key dates, see Delphi Code To Return Holidays, Observances, Celebrations, Historical, and Other Key Dates.
function PresidentsDay(TargetYear: Integer): TDate;
var
FebruaryMondayCount: Integer;
TargetDate: TDate;
begin
PresidentsDay := 0;

FebruaryMondayCount := 0;

TargetDate := 0;

TargetDate := StrToDate('2/1/'+IntToStr(TargetYear));
FebruaryMondayCount := 0;
If DayOfTheWeek(TargetDate) = 1 then FebruaryMondayCount := 1; //1 = Monday
repeat
TargetDate := TargetDate + 1;
If DayOfTheWeek(TargetDate) = 1 then FebruaryMondayCount := FebruaryMondayCount + 1;
until FebruaryMondayCount = 3;

PresidentsDay := TargetDate;
end;
The procedure below uses the function shown above to retrieve Presidents' 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', PresidentsDay(Year)));
end;
end;






Posted: Saturday, August 5, 2023