Eine kleine Programmieraufgabe zur Übung. Welcher Tag der Woche ist ein bestimmtes Datum. Dafür gibt es ein passende Formel auf Wikipedia. In CoDeSys kann diese leicht umgesetzt werden.
Die Deklaration:
PROGRAM PLC_PRG
VAR
d : INT:= 15; //day
m : INT:= 10; //month
y: INT:= 2018; //year
w: DINT; //result -> day of the week 1 = monday ...
END_VAR
Die Implementierung ist einfach:
IF (m < 3) THEN
y:= y - 1;
END_IF
w:= ((d + TRUNC(2.6 * ((m + 9) MOD 12 + 1) - 0.2) + y MOD 100
+ TRUNC(y MOD 100 / 4) + TRUNC(y / 400)
- 2 * TRUNC(y / 100) - 1) MOD 7 + 7) MOD 7 + 1;
In w steht anschließend der Tag der Woche. Z.B. 1 für Montag und so weiter.
