SIEMENS Driver DATE_AND_TIME values

@chi, I was trying to use your piece of code to read the time but can’t seem to understand exactly !

So, When I get the DATE and TIME in millis, at this point of time they are 11235 and 43640750 respectively. Now, from what you have., I understand that you want to shift binary of DATE to left by 32 bits to get the millis of date and then add millis of time into it. However, when I shift 32 bits left, my value is way too big (approx 188,535,312,519). Now, that value goes into the tag change event script and executed with binary. But, what comes out is nowhere close to current time.

Is there any reference to understand the DATETIME and binary conversion ?

Any help is appreciated.

This thread is about a special datatype in legacy Siemens plcs. Look at the first post for a description of that type.
Where did you get the values 11235 and 43640750 from? They don’t seem to be a date/time format i recognize.

From the original question I understand that the requirement is to read (and write) time to PLC. The PLC I am using is S7-300 with Simatic Manager.

As per the picture below, I have created DB tags to store both TOD(Time_Of_Day) and DATE(Which both seems to be in millisecond format). Now, I am trying to read this in Ignition by creating 2 different tags and combining them with expression but, it doesn’t seem to work.

image

Check the datatypes in the Siemens manuals. The original question in this thread is about the DATE_AND_TIME type.
You are using TOD, a 32 bit unsigned integer with milliseconds since midnight. DATE is 16 bit unsigned integer with days since 1990-01-01.
To convert it to a java time (milliseconds since 1970-01-01) you have to do some math (untested!):

631152000000+(DATE*24*60*60*1000)+TOD
# 631152000000 = milliseconds from 1970-01-01 to 1990-01-01
3 Likes

I am running into similar issues trying to get this data. Hoping the aforementioned tag change expression will end up working.

I also created a formal feature request for this since it seems like this should be something that exists.

1 Like

Has there been any traction with converting the DATE _AND_TIME bytes to a human readable datetime string?

After working with Customer Service, we came up with the following expression to use:

“20” + toHex({[.]BASIC_DATE_AND_TIME[0]}) + “-” + //Year, assuming in 21st century
numberFormat(toHex({[.]BASIC_DATE_AND_TIME[1]}), “00”) + “-” + //Month
numberFormat(toHex({[.]BASIC_DATE_AND_TIME[2]}), “00”) + “-” + //Day
numberFormat(toHex({[.]BASIC_DATE_AND_TIME[3]}), “00”) + “:” + //Hours
numberFormat(toHex({[.]BASIC_DATE_AND_TIME[4]}), “00”) + “:” + //Minutes
numberFormat(toHex({[.]BASIC_DATE_AND_TIME[5]}), “00”) + “:” + //Seconds
numberFormat(fromBinary(left(numberFormat(toBinary({[.]BASIC_DATE_AND_TIME[6]} + {[.]BASIC_DATE_AND_TIME[7]}), “0000000000000000”), 12)), “000”) + " " + //Milliseconds, it includes the first 4 bits of byte 7
case( //Day of the week, last 4 bits of byte 7
right(numberFormat(toBinary({[.]BASIC_DATE_AND_TIME[7]}), “00000000”), 4),
“0000”, “Sunday”,
“0001”, “Monday”,
“0010”, “Tueday”,
“0011”, “Wednesday”,
“0100”, “Thursday”,
“0101”, “Friday”,
“0111”, “Saturday”,
“Error - No Day Found”)

This worked to translate the old Siemens Date_And_Time data type to a string.

Hi, I came across this in the manual. It seems that you can get the date_and_Time format via the Siemens driver.

But a guess the only applies for the driver and not when you are using the OPC server interface in the Siemens PLC to access the tags?
Or am I'm missing something!

Not missing anything, that's correct.

Tanks.
Then I just have to do some PLC magic

There are one or two of the date/time types that are available over OPC UA with no fuss. I forget which ones... I can check in a bit.

edit: use LDT in the PLC, it gets exposed via the Siemens OPC UA Server as an OPC UA DateTime value.

1 Like

That's way more easy.
Thank you