Skip to content

Compare PLC DateTime - datatype

Hi all,


In my MQTT client i`ll subscribe on a topic which is an UTC timestamp, ISO8601 format: (2023-05-19T12:34:56Z)

I want to compare this time with the actual date and time from the controller, which is an datatype LDATE_AND_TIME (LDT#2023-05-31-15:14:10.705_291_008).


These values are from different data types, and i want to compare both timestamps with the logical function "Greater then".

On the subscribe function i cannot set the subscription tag to the same datatype as the PLC time, because the subscribtion won`t work when the format is not as expected.

I can declare the subscription tag as an STRING datatype and get the correct timestamp value (2023-05-19T12:34:56Z), but i cannot compare the STRING value with LDATE_AND_TIME value.


Can i convert one of these values into the other datatype to get equal datatypes which i can compare with an logical function?

IF readtimevalue <= plctimevalue THEN...

Comments

  • PLCNext Base Library (which doesn't actually come preinstalled with PLCNext Engineer AFAIK but you can download it from PLCNext Store) has a function that could help you: PBCL_DateTimeGetString_1 could be used to convert to the timestamp you need (or whatever other string)

    Another option I can think of is comparing it as an int. PLC's LDATE_AND_TIME is the number of nanoseconds since 1970 (need a 64 bit Int to fit). Or use a PBCL/your own function to convert to just seconds/miliseconds and compare that as an Int.

Sign In or Register to comment.