Einzelnen Beitrag anzeigen

ghubi01

Registriert seit: 18. Nov 2017
128 Beiträge
 
Delphi 12 Athens
 
#14

AW: Was haut bei dieser Wochentagsberechnung nicht hin?

  Alt 27. Okt 2018, 14:42
Hallo Ave,

versuch das mal

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  JahrInt,JahrIntLow,JahrIntHigh,
  b1,b2,b3,b4,
  Day,DayI,
  Monat:integer;
  JahrStr: string;
begin

    JahrInt:=strtoint(edit1.Text); // vierstellige Jahreszahl!
    Day:=strtoint(edit2.Text); // Tag
    Monat:=strtoint(edit3.Text); // Monat

    b1:=5*((JahrInt-1) mod 4)+1; // nach: Carl Friedrich Gauss
    b2:=4*((JahrInt-1) mod 100);
    b3:=6*((JahrInt-1) mod 400);
    b4:= (b1+b2+b3) mod 7;

    case b4 of
    0: label1.caption:='Sonntag';
    1: label1.caption:='Montag';
    2: label1.caption:='Dienstag';
    3: label1.caption:='Mittwoch';
    4: label1.caption:='Donnerstag';
    5: label1.caption:='Freitag';
    6: label1.caption:='Samstag';
    end;

    // Informationsquelle für die nachfolgenden Bererchnungen:
    // https://de.wikipedia.org/wiki/Wochentagsberechnung
    if Monat < 3 then
    begin
      Monat:= Monat + 10;
      dec(JahrInt); // oder JahrInt:= JahrInt - 1;
    end else dec(Monat,2); // oder Monat:= Monat - 2;

    JahrStr:=IntToStr(JahrInt);
    JahrIntHigh:=StrToInt(Copy(JahrStr,1,2));
    JahrIntLow:=StrToInt(Copy(JahrStr,3,2));

    // Unit Math (Lazarus) oder System.Math (Delphi) einbinden
    DayI:=(Day+Floor(2.6*Monat-0.2)+JahrIntLow+Floor(JahrIntLow/4)+Floor(JahrIntHigh/4)-2*JahrIntHigh) mod 7;
    if DayI<0 then DayI:=DayI + 7;

    case DayI of
    0: label2.caption:='Sonntag';
    1: label2.caption:='Montag';
    2: label2.caption:='Dienstag';
    3: label2.caption:='Mittwoch';
    4: label2.caption:='Donnerstag';
    5: label2.caption:='Freitag';
    6: label2.caption:='Samstag';
    end;
end;
  Mit Zitat antworten Zitat