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

Mother's Day - Second Sunday in May
Here is a simple Delphi function that takes a year as its input and returns the date for Mother's Day (second Sunday in May), a very special day for each of us to recognize our mother. Mark your calendar and be sure to do something special for your mom 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 MothersDay(TargetYear: Integer): TDate;
var
SundayCount: Integer;
TargetDate: TDate;
begin
MothersDay := 0;

SundayCount := 0;

TargetDate := 0;

TargetDate := StrToDate('5/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 = 2;

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






Posted: Tuesday, December 3, 2024