Ask Me About Webinar: Data Center Assets - Modeling, Cooling, and CFD Simulation
Join our 30-minute expert session on July 10, 2025 (9:00 AM & 5:00 PM CET), to explore Digital Twins, cooling simulations, and IT infrastructure modeling. Learn how to boost resiliency and plan power capacity effectively. Register now to secure your spot!
Access vast amounts of technical know-how and pro tips from our community of Geo SCADA experts.
Search in
Link copied. Please paste this link to share this article on your social media post.
Originally published on Geo SCADA Knowledge Base by Anonymous user | June 10, 2021 12:58 AM
Logic that returns the day of the week as a number (0 = Sunday to 6 = Saturday).
FUNCTION_BLOCK DayOfTheWeek
VAR_INPUT
InDate : DATE_AND_TIME;
END_VAR
VAR_OUTPUT
DayOfWeek : INT;
END_VAR
VAR
Year : INT;
cYear : INT;
Month : INT;
Day : INT;
CP : INT;
YP : INT;
MP : INT;
LeapYear : BOOL := FALSE;
Valid :BOOL;
END_VAR
Year := EXTRACT_DT_YEAR(InDate);
cYear := STRING_TO_INT(RIGHT(INT_TO_STRING(Year),2));
Month := EXTRACT_DT_MONTH(InDate);
Day := EXTRACT_DT_DAY(InDate);
Valid := TRUE;
CASE Year OF
1752..1799 : CP := 4;
1800..1899 : CP := 2;
1900..1999 : CP := 0;
2000..2099 : CP := 6;
ELSE
Valid := FALSE;
END_CASE;
YP := cYear / 4;
IF (MOD(cYear,400) = 0) THEN
LeapYear := TRUE;
ELSIF (MOD(cYear,100) = 0) THEN
LeapYear := FALSE;
ELSIF (MOD(cYear,4) = 0) THEN
LeapYear := TRUE;
ELSE
LeapYear := FALSE;
END_IF;
CASE Month OF
1 :
IF LeapYear THEN
MP := 6;
ELSE
MP := 0;
END_IF;
2 :
IF LeapYear THEN
MP := 2;
ELSE
MP := 3;
END_IF;
3 : MP := 3;
4 : MP := 6;
5 : MP := 1;
6 : MP := 4;
7 : MP := 6;
8 : MP := 2;
9 : MP := 5;
10 : MP := 0;
11 : MP := 3;
12 : MP := 5;
END_CASE;
IF Valid THEN
DayOfWeek := MOD(CP + cYear + YP + MP + Day, 7 );
ELSE
DayOfWeek := -1;
END_IF;
END_FUNCTION_BLOCK
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.