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

Martin Luther King Jr. Day - Third Monday in January
Here is a simple Delphi function that takes a year as its input and returns the date for Martin Luther King Jr. Day (third Monday in January). For additional Delphi code to return key dates, see Delphi Code To Return Holidays, Observances, Celebrations, Historical, and Other Key Dates.
function MartinLutherKingJrDay(TargetYear: Integer): TDate;
JanuaryMondayCount: Integer;
TargetDate: TDate;
MartinLutherKingJrDay := 0;

JanuaryMondayCount := 0;

TargetDate := 0;

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

MartinLutherKingJrDay := TargetDate;
The procedure below uses the function shown above to retrieve Martin Luther King Jr. 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);
Year: Integer;
For Year := 2000 to 2100 do
Memo1.Lines.Add(FormatDateTime('dddd, mmmm d, yyyy', MartinLutherKingJrDay(Year)));

Posted: Sunday, June 25, 2023
Last updated: Tuesday, July 4, 2023