Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84534members
353788posts

Structured Text - Need to Subtract 1y from DT in ST Logic

EcoStruxure Geo SCADA Expert Forum

Find out how SCADA systems and networks, like EcoStruxure Geo SCADA Expert, help industrial organizations maintaining efficiency, processing data for smarter decision making with IoT, RTU and PLC devices.

Solved
kvacola
Crewman
Crewman
0 Likes
5
2017

Structured Text - Need to Subtract 1y from DT in ST Logic

[Using ClearSCADA 2017 R3]

 

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:

 

 

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);

 

 

But the final function that compares the current time to the calculated time is giving me the error 'Program Error: Invalid conversion'

 

 

IF DATETIME > dtCurrentTime THEN
	DATETIME	:= SUB_DT_TIME(DATETIME, STRING_TO_TIME('D#1y'));
END_IF;

 

 

The program compiles just fine, I only get the error when I execute the program.


Accepted Solutions
AdamWoodland
Commander Commander
Commander
0 Likes
0
1996

Re: Structured Text - Need to Subtract 1y from DT in ST Logic

Might have been able to get away with:

 

DATETIME := SUB_DT_TIME(DATETIME, T#365d);

 

Although would need to take leap years into account.

See Answer In Context

5 Replies 5
BevanWeiss
Spock
Spock
0 Likes
4
2013

Re: Structured Text - Need to Subtract 1y from DT in ST Logic

If these are all INTs... why are you doing anything with STRINGs?

 

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;

 

 

 


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
kvacola
Crewman
Crewman
0 Likes
3
2009

Re: Structured Text - Need to Subtract 1y from DT in ST Logic

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.

AdamWoodland
Commander Commander
Commander
0 Likes
0
1997

Re: Structured Text - Need to Subtract 1y from DT in ST Logic

Might have been able to get away with:

 

DATETIME := SUB_DT_TIME(DATETIME, T#365d);

 

Although would need to take leap years into account.

BevanWeiss
Spock
Spock
0 Likes
1
1993

Re: Structured Text - Need to Subtract 1y from DT in ST Logic

@kvacola How did you get somewhat good syntax colouring on your ST Logic text?  Did you have to colour it yourself?

 

@AdamWoodland 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?


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
sbeadle
Janeway Janeway
Janeway
0 Likes
0
1983

Re: Structured Text - Need to Subtract 1y from DT in ST Logic

That was 'C' language colouring. Colours function names red but is unaware of  (* *) comments.

 

Time and its text representations support, for example, a century's worth of seconds in Adam's example.