converting current date to string

pug

Member
Join Date
Oct 2002
Posts
5
I'm using a Simatic 400 (CPU 414-2 DP) in S7.
Now i want to use the current date with the READ_CLK SFC1 function and transfer this into a string in the format dd-mm-yyyy (for using it with a Scada application).

How can i solve this ?
 
There are two SFCs available for viewing and setting the time from the user program:
· SFC0 SET_CLK : set time
· SFC1 READ_CLK : view time
The following is an example for parameterizing and calling these SFCs:
Configuration of date and time (=parameters PDT and CDT)

Byte n YEAR MONTH Byte n+1
Byte n+2 DAY HOUR Byte n+3
Byte n+4 MINUTE SECOND Byte n+5
Byte n+6 MS_HUNDREDS MS_TENS MS_UNITS DAY OF WEEK Byte n+7

.
The values are to be specified in BCD-code.

Day of week code: 1 = Sunday ... 7 = Saturday

Example SFC 0 SET_CLK
The "date_time" variable is defined as local variable as of LB20 and is of the type DATE_AND_TIME (DT).
Date: 19th November 1996; Tuesday => code = 3
Time: 07:05:00
L DW#16#96111907;
T LD20;
L DW#16#05000003;
T LD24;
CALL SFC 0 (
PDT := date_time,
RET_VAL := MW0
);

Example SFC1 READ_CLK
The "date_time" variable is defined as local variable as of LB20 and is of the type DATE_AND_TIME (DT).

CALL SFC 1 (
CDT := date_time,
RET_VAL := MW2
);

Date and time are to be entered in BCD code in the "date_time" variable according to the table given above.
 
Thanks but isn't there a posibility to place then date into a string in the format dd-mm-yyyy ?
 
Generally, SCADA software packages give you a lot of flexibility in displaying values. If the function call returns the day, month, and year in BCD, why can't the SCADA read the returned values and do the formatting? What package are you using?
 
Pug
FC16 in the 'StdLib30' is I_STRNG. A standard block that converts integer to a string. You may have to call it 3 times to get the year, month and date, but if you put these in consecutive bytes, they can be concatenated (good word eh?) to form one string.
Before I knew about this I converted integers to ASCII myself.
Adding 48 to and integer gives the ASCII equivalent eg.
0 - 48
1 - 49
Only works for integers 0-9 though.
 
Thanks, i'm getting closer, if i use the covert to string function, i'm having a sign from the integer, how can i delete this sign ?
 
Hi Pug
FC20 (LEFT) and FC32 (RIGHT) can be used to extract characters from the right of left of a string.
Can you use this to extract the characters you're interested in?
Once they're extracted, they can be assembled using FC2 CONCAT to make one string.
 

Similar Topics

hi friends, my friends told that conversion of analog voltage module to current module is possible using connecting resistors in inputs. is it...
Replies
6
Views
3,585
Hi guys, I'm sizing up a Micrologix 1400 and their base itself comes with 4 AI & 2 AO, but all a voltage type (0-10V), is there anywhere we can...
Replies
6
Views
3,093
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
208
Hello PLCs Forum, I am in a bit of a pickle and was hoping someone could offer me some help. I have a .rss file and just need to see the ladder...
Replies
2
Views
122
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
317
Back
Top Bottom