Showing results 1 to 3 of 3

Thread: STRING to TIME

  1. #1
    Join Date
    27.08.2015
    Posts
    8

    Default STRING to TIME

    Hi All,

    I read a string from *.csv file : 15-05-2019 09:00

    How can I change this STRING to the right time?

    I used ANY_TO_TIME, I just only get time==15ms.

    Thanks.

  2. #2
    Join Date
    25.06.2012
    Posts
    155
    Best Answer

    Default Re: STRING to TIME

    Dear kieuminh,

    it is possible to convert STRING to TIME using the ANY_TO_TIME function but the input STRING must follow a specific input format, so that the XX..X digits will be converted to T#.....h...m..s...ms.

    You can find more detailed information in zenon Logic help about the ANY_TO_TIME function:

    Programming languages - Reference guide -> Type conversion functions -> ANY_TO_TIME 

    If you want to extrat the respective UNIX time from the STRING you can use the DT2UNIX function together with the MID (Extracts characters from text) and save the output in a LREAL variable (UNIX).

    In this case, you can use STRING functions to assign the respective DD-MM-YYYY HH:mm to a TIME variable as below:

    OUTTIME := DT2UNIX(ANY_TO_DINT(MID(CSVTIME,4,7)), ANY_TO_DINT(MID(CSVTIME,2,4)), ANY_TO_DINT(MID(CSVTIME,2,1)), ANY_TO_DINT(MID(CSVTIME,2,12)), ANY_TO_DINT(MID(CSVTIME,2,15)), 0, 0, 0, 0);

    I used the following variable definition for testing:

    VAR
       CSVTIME : STRING(255) := '15-05-2019 09:00' ;
       OUTTIME : LREAL ;
    END_VAR

    The code above can be part of function block to be easily reusable.

    Good luck,

    David Cerdeira

  3. #3
    Join Date
    27.08.2015
    Posts
    8

    Default Re: STRING to TIME

    Thank you very much, David.

Similar Threads

  1. Replies: 2
    Last Post: 22nd February 2016, 09:39
  2. Copying a string to another string
    By mjackson in forum zenon Supervisor
    Replies: 1
    Last Post: 22nd December 2014, 20:22
  3. Read Date & Time from Time Attribute on IEC61850
    By salmanhassan2 in forum zenon Energy Edition
    Replies: 4
    Last Post: 22nd February 2013, 07:34
  4. Read Date & Time from Time Attribute on IEC61850
    By salmanhassan2 in forum Drivers
    Replies: 4
    Last Post: 22nd February 2013, 07:34
  5. String length field for STRING variables.
    By stolyarov_as in forum zenon Supervisor
    Replies: 3
    Last Post: 11th January 2013, 07:49

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •