topic Re: Structured Text - Need to Subtract 1y from DT in ST Logic in Geo SCADA Expert Forum
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/191011#M1176
<P>That was 'C' language colouring. Colours function names red but is unaware of (* *) comments.</P><P> </P><P>Time and its text representations support, for example, a century's worth of seconds in Adam's example.</P>Wed, 04 Mar 2020 10:21:13 GMTsbeadle2020-03-04T10:21:13ZStructured Text - Need to Subtract 1y from DT in ST Logic
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190947#M1164
<P>[Using ClearSCADA 2017 R3]</P><P> </P><P>I have a structured text program that is calculating a date and time from 2 FloBoss integers. INT1 is the Date (without year) and is a 4-digit value (e.g. 0226). INT2 is the 4-digit Time in 24h format (e.g. 1442). I've successfully gotten to the point in my ST program where I have the date. Unfortunately for dates that straddle the year for this device, I need to be able to subtract 1 year from the date. I use the current date and time to extract 'YEAR' and do a couple of concatenations to get the time:</P><P> </P><P> </P><LI-CODE lang="c">dtDate := MAKE_DATE(YEAR, STRING_TO_SINT(strMonth), STRING_TO_SINT(strDay));
dtTime := MAKE_TIME_OF_DAY(STRING_TO_SINT(strHour), STRING_TO_SINT(strMins), 0, 0);
DATETIME := CONCAT_D_TOD(dtDate, dtTime);</LI-CODE><P> </P><P> </P><P>But the final function that compares the current time to the calculated time is giving me the error 'Program Error: Invalid conversion'</P><P> </P><P> </P><LI-CODE lang="c">IF DATETIME > dtCurrentTime THEN
DATETIME := SUB_DT_TIME(DATETIME, STRING_TO_TIME('D#1y'));
END_IF;</LI-CODE><P> </P><P> </P><P>The program compiles just fine, I only get the error when I execute the program.</P>Tue, 03 Mar 2020 18:57:44 GMThttps://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190947#M1164kvacola2020-03-03T18:57:44ZRe: Structured Text - Need to Subtract 1y from DT in ST Logic
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190950#M1165
<P>If these are all INTs... why are you doing anything with STRINGs?</P><P> </P><LI-CODE lang="markup">CURR_INT1 := EXTRACT_DT_MONTH(NOW()) * 100 + EXTRACT_DT_DAY(NOW());
CURR_INT2 := EXTRACT_DT_HOUR(NOW()) *100 + EXTRACT_DT_MINUTE(NOW());
IF( CURR_INT1 > INT1 OR (CURR_INT1 = INT1 AND CURR_INT2 >= INT2)) THEN
(* Our datetime event was this year.. *)
(* We don't care about Seconds / Milliseconds, so set these to zero *)
(* INT1 = MMDD, INT2 = HHMM *)
DATETIME := MAKE_DATE_AND_TIME( YEAR, DIV( INT1, 100), MOD(INT1,100), DIV(INT2,100), MOD(INT2,100), 0, 0 );
ELSE
(* our datetime event was last year *)
(* We don't care about Seconds / Milliseconds, so set these to zero *)
(* INT1 = MMDD, INT2 = HHMM *)
DATETIME := MAKE_DATE_AND_TIME( YEAR - 1, DIV( INT1, 100), MOD(INT1,100), DIV(INT2,100), MOD(INT2,100), 0, 0 );
END_IF;</LI-CODE><P> </P><P> </P><P> </P>Tue, 03 Mar 2020 20:09:43 GMThttps://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190950#M1165BevanWeiss2020-03-03T20:09:43ZRe: Structured Text - Need to Subtract 1y from DT in ST Logic
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190957#M1166
<P>That did the trick! Thanks so much. I though I'd have to convert to strings to parse off the month/day and hour/min.</P>Tue, 03 Mar 2020 20:57:12 GMThttps://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190957#M1166kvacola2020-03-03T20:57:12ZRe: Structured Text - Need to Subtract 1y from DT in ST Logic
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190978#M1170
<P>Might have been able to get away with:</P><P> </P><P>DATETIME := SUB_DT_TIME(DATETIME, T#365d);</P><P> </P><P>Although would need to take leap years into account.</P>Wed, 04 Mar 2020 07:23:16 GMThttps://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190978#M1170AdamWoodland2020-03-04T07:23:16ZRe: Structured Text - Need to Subtract 1y from DT in ST Logic
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190980#M1171
<P><LI-USER uid="39574"></LI-USER> How did you get somewhat good syntax colouring on your ST Logic text? Did you have to colour it yourself?</P><P> </P><P><LI-USER uid="38386"></LI-USER> It is a little frustrating that the logic engine (and many parts of ClearSCADA) can't do subtraction of things like months / years etc (conceptual time periods). I was a bit afraid that 1year in days would overflow the holding of the 'Time' datatype. What is the extent of what it can hold?</P>Wed, 04 Mar 2020 07:37:24 GMThttps://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/190980#M1171BevanWeiss2020-03-04T07:37:24ZRe: Structured Text - Need to Subtract 1y from DT in ST Logic
https://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/191011#M1176
<P>That was 'C' language colouring. Colours function names red but is unaware of (* *) comments.</P><P> </P><P>Time and its text representations support, for example, a century's worth of seconds in Adam's example.</P>Wed, 04 Mar 2020 10:21:13 GMThttps://community.exchange.se.com/t5/Geo-SCADA-Expert-Forum/Structured-Text-Need-to-Subtract-1y-from-DT-in-ST-Logic/m-p/191011#M1176sbeadle2020-03-04T10:21:13Z