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

Father's Day - Third Sunday in June
Here is a simple Delphi function that takes a year as its input and returns the date for Father's Day (third Sunday in June), a day for each of us to recognize our father. Mark your calendar and be sure to do something special for your dad on this day! For additional Delphi code to return key dates, see Delphi Code To Return Holidays, Observances, Celebrations, Historical, and Other Key Dates.
function FathersDay(TargetYear: Integer): TDate;
var
SundayCount: Integer;
TargetDate: TDate;
begin
FathersDay := 0;

SundayCount := 0;

TargetDate := 0;

TargetDate := StrToDate('6/1/'+IntToStr(TargetYear));
If DayOfTheWeek(TargetDate) = 7 then SundayCount := 1; //7 = Sunday
repeat
TargetDate := TargetDate + 1;
If DayOfTheWeek(TargetDate) = 7 then SundayCount := SundayCount + 1;
until SundayCount = 3;

FathersDay := 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', FathersDay(Year)));
end;
end;






Posted: Tuesday, December 3, 2024