Skip to content

Convert String to LDT

I try to convert a STRING into a LDATE_AND_TIME. I am struggeling with the BUF_CNT input. Does someone know what I have to attach here?

Status 3 means that the BUF_CNT is larger than the destination buffer.

Comments

  • edited January 2024

    Hello!

    Actually, LDT has 8 byte length. And when you try to mix characters codes of ascii symbols and binary encoded timestamp, it does not work as expected. It seems that you have to extract certain parts of string, year, month, day, hour etc, convert it to numerical valuer and then use CONCAT_LDT function.

    Some time ago I play around similar task (parsing string time). Please find sample code attached.

    If you find out more strict way, based on embeded fc/fb or some official libraries, please let me know.

    Best regards

  • edited January 2024

    One more way to implement this function is to use shell command date, via PLCnexBase library block. It benefit will be additional validity control of string date data. But it require initiation of interaction with cli, and block will operate in async mode.

    String date converted via shell command date -d "YOUR DATE" +%s to unix timestamp (as string number), next timestamp convert to UDINT, and next convert to LDT via PBCL_DateTimeFromUnix_1 function of PLCnexBase library.

    Please, find fb sample attached.


    Best regards.

Sign In or Register to comment.