TIA Portal YYYYMMDD to Date or DTL

JohanM

Member
Join Date
Sep 2015
Location
Terchová
Posts
53
Hi guys

I am crossing internet two days, but I can not find something really helpful for me..

I have this problem:

I have to read expiration date from EKS key and compare it with actual PLC date. That date in EKS is coded to 8 bytes character by character YYYYMMDD..I can read that bytes, I can convert it from ASCII, but I dont know, how to convert it to Date format or DTL.. Can someone help me with this? 🤞🏻
 
Last edited:
There are many ways to do this, but you could convert the parts of the input string to internal DTL formats and convert again to date-format in order to compare YYYYMMDD.

String conversion can be a bit troublesome, but it's doable.
I have a working solution, but try it yourself first.

Here's a hint:
(*Convert string to UINT (.Year datatype). Input the 4 Chars (L) starting from char 1 (P)*)
#TestDTL.YEAR := STRING_TO_UINT(IN := MID(IN := #InputDate, L := 4, P := 1));
 
Last edited:
Since you have the bytes char by char, you probably have an Array[0..7] of CHAR that you can convert with CHARS_TO_STRG. Either to one complete string[8] or 3 separate strings for year, month, and day. After that you can convert to UINT/USINT.

Since you'll (probably) read the system time with RD_SYS_T or RD_LOC_T you'll have your current date in DTL format. Convert it to DATE with DTL_TO_DATE before you compare, otherwise you'll also compare the time of day, when you are only interested in the date.

You could also compare your CurrentDTL.Year with your TestDTL.Year and so on with .Month and .Day. You'll save a few conversions that way, but will do several comparisons instead.

OR you could also convert your CurrentDTL to strings and compare the other way around, but then you'll have to do padding with leading zeros for the month and day.

As you see, there are many ways to do it :)
 
Since you have the bytes char by char, you probably have an Array[0..7] of CHAR that you can convert with CHARS_TO_STRG. Either to one complete string[8] or 3 separate strings for year, month, and day. After that you can convert to UINT/USINT.

Since you'll (probably) read the system time with RD_SYS_T or RD_LOC_T you'll have your current date in DTL format. Convert it to DATE with DTL_TO_DATE before you compare, otherwise you'll also compare the time of day, when you are only interested in the date.

You could also compare your CurrentDTL.Year with your TestDTL.Year and so on with .Month and .Day. You'll save a few conversions that way, but will do several comparisons instead.

OR you could also convert your CurrentDTL to strings and compare the other way around, but then you'll have to do padding with leading zeros for the month and day.

As you see, there are many ways to do it :)

Thank you my friend!
I got solution from huggy_1 from Siemens forum. It is basicly what you suggested to me. Many thanks to you guys!🍻

"
FUNCTION "EKS_DateToDTL" : Void
TITLE = EKS Date to DTL
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : huggy_d1
FAMILY : EKS
NAME : FORUMS
VERSION : 0.1
//Accept EKS Date char array [YYYYMMDD] as input
//Output EKS Date as DTL tag
VAR_INPUT
EKS_Date : Array[0..7] of Char;
END_VAR
VAR_OUTPUT
EKS_DTL {OriginalPartName := 'DTL'; LibVersion := '1.0'} : DTL;
END_VAR
VAR_TEMP
EKS_String : String[8];
yyyy_string : String[4];
mm_string : String[2];
dd_string : String[2];
END_VAR

BEGIN
// convert YYYMMDD ASCII char array into a string
Chars_TO_Strg(Chars:=#EKS_Date,
pChars:=0,
Cnt:=8,
Strg=>#EKS_String);

// parse EKS_string to obtain YYYY, MM, DD as strings
#yyyy_string := LEFT(IN := #EKS_String, L := 4);
#mm_string := MID(IN := #EKS_String, L := 2, P := 5);
#dd_string := RIGHT(IN := #EKS_String, L := 2);
#EKS_DTL.YEAR := STRING_TO_UINT(IN:=#yyyy_string);
#EKS_DTL.MONTH := STRING_TO_USINT(IN:=#mm_string);
#EKS_DTL.DAY := STRING_TO_USINT(IN:=#dd_string);

END_FUNCTION


"


 

Similar Topics

Im trying to create a level indicator for water Tank i have used the ADD function while the pump is on and level increasing everything works...
Replies
12
Views
76
My PLC (S7-1200 with CPU-1212C) has now been delivered to customer site. They've asked me to do some updates to the software. I can do that on my...
Replies
21
Views
330
Does anyone know why the connection interface is greyed out and says why I can only use Teleservice instead of the other options like PN/IE? I am...
Replies
0
Views
44
Hi guys I after a bit of advice on Tia portal graphics, I would like to add a conveyor belt graphic to a hmi and the conveyor in the basic...
Replies
3
Views
130
Hi I used to be able to launch PLCsim without any problem. Now it tells me " STEP 7 Professional Licence is required to simulate this PLC"...
Replies
15
Views
453
Back
Top Bottom