Return the day of the week
DAY_OF_WEEK0 returns the day of the week for any date as an INT. The number 0 corresponds to Sunday, 6 to Saturday.
Input
Date
Output
0 (Sunday) – 6 (Saturday)
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
DATE_value: DATE:=D#2014-04-20;
iDAY_OF_WEEK_value: INT:=0;
END_VAR
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,DAY_OF_WEEK0!,,9,2,18,4,,?D?C);
B(B_VARIN,,DATE_value,7,2,9,4,);
B(B_VAROUT,,iDAY_OF_WEEK_value,18,2,20,4,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
The value iDAY_OF_WEEK_value = 0 corresponds to Sunday.
If you need an offset of five days, e.g. 5 corresponds to Sunday:
iDAY_OF_WEEK_value := DAY_OF_WEEK0(DATE_value);
(* if you want a time offset of 5 days, e.g. Sunday corresponds to 5 *)
iDAY_OF_WEEK_value := DAY_OF_WEEK0(DATE_value )+ 5 MOD 7;