How to calculate the future occurrences of Friday the 13th in Pascal

1 Answer

0 votes
program FridayThe13ths;

uses
  SysUtils, DateUtils;

procedure FindFridayThe13ths(startYear, endYear: Integer);
var
  year, month: Integer;
  dt: TDateTime;
begin
  for year := startYear to endYear do
  begin
    for month := 1 to 12 do
    begin
      dt := EncodeDate(year, month, 13);
      if DayOfWeek(dt) = 6 then // 6 corresponds to Friday in Pascal's DayOfWeek function
        Writeln('Friday the 13th: ', year, '-', Format('%.2d', [month]), '-13');
    end;
  end;
end;

begin
  FindFridayThe13ths(2025, 2031);
end.

   
     
(*
run:
 
Friday the 13th: 2025-06-13
Friday the 13th: 2026-02-13
Friday the 13th: 2026-03-13
Friday the 13th: 2026-11-13
Friday the 13th: 2027-08-13
Friday the 13th: 2028-10-13
Friday the 13th: 2029-04-13
Friday the 13th: 2029-07-13
Friday the 13th: 2030-09-13
Friday the 13th: 2030-12-13
Friday the 13th: 2031-06-13
     
*)

 



answered May 31, 2025 by avibootz
...