Date/Time Stamp - Siemens S7-300

AshleyParr

Member
Join Date
Dec 2008
Location
Midlands, UK
Posts
184
Ok then guys after a lot of looking around for an answer on this subject i feel very dizzy and amazed it appears so hard to be able to create a time stamp in Siemens!!

All i want to do is log when the filler starts, preferably in the format dd-mm-yyy hh:mm:ss . Is there an easy way to do this?

I've looked at reading the plc clock, then using time/date/time of day. All end up working okish but are not formatted, so as soon as i try to display on a screen its nonsense. Ive done something similar in AB, converting the data to strings then concatenating them

Any suggestions?
 
Can you use Date and Time-format, which PLC clock allready has?
You need to copy indirectly 4 ints to Date and format variable.
 
I typically use the built in formats.

SFC1 - READ_CLK will get you the date and time in 'date_and_time' format. yyyy-mm-dd-hh:mm:ss:mmm this format makes most sense to me (and I believe to the PLC) since it reads from most significant on the left to least significant on the right. Easier to do comparisons with. This is a complex data type so not viewable in a datablock.

So you would have to break it out to 'DATE' and 'TIME_OF_DAY' formats using the built in FCs ( FC6 - 'DT to DATE', FC8 - 'DT to TOD'

I am not aware of any functions to format the date otherwise. For display purposes you could pull out month , day , year separately into their own INTs?
 
you can copy Date and time format to separate varibales also with using local temp memory or using AR1 / AR2

Read first PLC time to DATE and time format to L-memory (temp address with Lx)

The move from temp memory to 8 separate variables (move Lx memory to DB addresses or use indirect copy with AR1

If you have DATE_AND_Time variable on temp address with address L0 then on temp memory you have on these addresses (BCD format):
LB0 = year
LB1 = month
LB2 = day
LB3 = hour
LB4 = minute
LB5 = second
LB6 = msecond
LB7 = day of week
 
Thanks for the replies so far guys. I already have split the DT out into bytes in a DB but have been stuggling to get this timestamp in a readable format.

I have just knocked this up but still get odd readings:

Code:
//Get PLC Clock Information
      CALL  "READ_CLK"
       RET_VAL:=MW100
       CDT    :="MiscFunctions".Filler_DT

      CALL  "DT_DATE"
       IN     :="MiscFunctions".Filler_DT
       RET_VAL:="MiscFunctions".Filler_StartDate

      CALL  "DT_TOD"
       IN     :="MiscFunctions".Filler_DT
       RET_VAL:="MiscFunctions".Filler_StartTime

Below are the returned results in a variable table
DB30.DBD 18 "MiscFunctions".Filler_StartTime TIME_OF_DAY TOD#04:39:37.312
DB30.DBW 22 "MiscFunctions".Filler_StartDate DATE D#1990-09-14

Edit: I should note that its currently 2pm here in 2016, not 1990 :D

Ash
 
Last edited:
if you look "MiscFunctions".Filler_DT byte addresses, is there year 1990 or 2016

And of course you have checked that PLC have right time (y)
 
If your PLC's time is synchronized then you can just use the date/time in OB1.
If your PLC's time is NOT synchronized, you can still do this, but you'll have to manually ensure the correctness of the time.

LB12: Year (00 - 99 for 1990 - 2089)
LB13: Month (01 - 12)
LB14: Day (01 - 31)
LB15: Hour (00 - 23)
LB16: Minute (00 - 59)
LB17: Second (00 - 59)
LW18: Special ->
First(most significant) 12bits: ms (000 - 999)
Last(least significant) 4 bits: Day of week (1 - 7, 1=Sunday)

All these values are in BCD.
We store these individual values as BCD, INT and combined as Date/Time so we can use whatever type we need.
To display on screens, we make an IO-field/tag per values, in your case that would be 6 IO-fields/tags.

You could always convert to Int, convert to string, concat strings in whatever sequence you need.

Quick and dirty:
Code:
Declare string[19] at DB1.DBB0
DB1.DBB0:= 19
DB1.DBB1:= 19
DB1.DBB2:= (LB14 / 16) + 48 
DB1.DBB3:= (LB14 Mod 16) + 48
DB1.DBB4:= '-'
DB1.DBB5:= (LB13 / 16) + 48 
DB1.DBB6:= (LB13 Mod 16) + 48
DB1.DBB7:= '-'
DB1.DBB8:= '2'
DB1.DBB9:= '0'
DB1.DBB10:= (LB12 / 16) + 48 
DB1.DBB11:= (LB12 Mod 16) + 48
DB1.DBB12:= ' '
DB1.DBB13:= (LB15 / 16) + 48 
DB1.DBB14:= (LB15 Mod 16) + 48
DB1.DBB15:= ':'
DB1.DBB16:= (LB16 / 16) + 48 
DB1.DBB17:= (LB16 Mod 16) + 48
DB1.DBB18:= ':'
DB1.DBB19:= (LB17 / 16) + 48 
DB1.DBB20:= (LB17 Mod 16) + 48

Results in 'DD-MM-YYYY HH:MM:SS'.
(or should at least :D)
 
if you look "MiscFunctions".Filler_DT byte addresses, is there year 1990 or 2016

And of course you have checked that PLC have right time (y)

Haha yes i have 16 in the byte address & the PLC does have the correct time. That was my first check before posting :ROFLMAO:
 
If your PLC's time is synchronized then you can just use the date/time in OB1.
If your PLC's time is NOT synchronized, you can still do this, but you'll have to manually ensure the correctness of the time.

LB12: Year (00 - 99 for 1990 - 2089)
LB13: Month (01 - 12)
LB14: Day (01 - 31)
LB15: Hour (00 - 23)
LB16: Minute (00 - 59)
LB17: Second (00 - 59)
LW18: Special ->
First(most significant) 12bits: ms (000 - 999)
Last(least significant) 4 bits: Day of week (1 - 7, 1=Sunday)

All these values are in BCD.
We store these individual values as BCD, INT and combined as Date/Time so we can use whatever type we need.
To display on screens, we make an IO-field/tag per values, in your case that would be 6 IO-fields/tags.

You could always convert to Int, convert to string, concat strings in whatever sequence you need.

Quick and dirty:
Code:
Declare string[19] at DB1.DBB0
DB1.DBB0:= 19
DB1.DBB1:= 19
DB1.DBB2:= (LB14 / 16) + 48 
DB1.DBB3:= (LB14 Mod 16) + 48
DB1.DBB4:= '-'
DB1.DBB5:= (LB13 / 16) + 48 
DB1.DBB6:= (LB13 Mod 16) + 48
DB1.DBB7:= '-'
DB1.DBB8:= '2'
DB1.DBB9:= '0'
DB1.DBB10:= (LB12 / 16) + 48 
DB1.DBB11:= (LB12 Mod 16) + 48
DB1.DBB12:= ' '
DB1.DBB13:= (LB15 / 16) + 48 
DB1.DBB14:= (LB15 Mod 16) + 48
DB1.DBB15:= ':'
DB1.DBB16:= (LB16 / 16) + 48 
DB1.DBB17:= (LB16 Mod 16) + 48
DB1.DBB18:= ':'
DB1.DBB19:= (LB17 / 16) + 48 
DB1.DBB20:= (LB17 Mod 16) + 48

Results in 'DD-MM-YYYY HH:MM:SS'.
(or should at least :D)

Thanks. Ill take a look into that. Not quite sure why the DT to Date & TOD isnt working though
 
1990 is the default start year in the PLC. I would double check under 'PLC -> Set Time Of Day' that it is correct (if required 'take time from PG/PC').

Maybe it accidentally got reset somehow.

I attached what my 'Set Time Of Day' and results from READ_CLK (and breaking it apart) look like.

DateAndTime.jpg
 
Is there any value in the return code of the READ_CLK?

Can you take a screen shot of that being monitored?
 

Similar Topics

So I've got an issue I have yet to figure out. I have a PVPlus standard HMI runtime v12. I've gone into the system and set the date and time and...
Replies
7
Views
4,816
Dear Members; I make a date and time stamp by using GSV and SSV instructions. The DINT array with 7 elements stores those values. Now I want to...
Replies
5
Views
1,512
I am trying to display the time stamp from an FBD Analog alarm on FT View ME. I tried copying the Stamp over to a time structure like I do when...
Replies
0
Views
1,257
Hi folks. First time I've tried to do this. I am using rs5K V.28 and change, FTV ME V.8.0. I have a project that entails moving values into...
Replies
4
Views
1,783
Im using studio 5000 for a project and have a string that contains the date. I was wondering if someone as figued out how to get a new target date...
Replies
1
Views
1,948
Back
Top Bottom