Search code examples
stlcodesys

Split the date and time from string in codesys v 3


i 'm working on codesys . I have a string which has the DATE AND TIME .I want to split the date and time . currentTime: DATE_AND_TIME; showing value like this DT#2019-08-06-10:06:53 after concat Convert the currentTime variable into string .

Now i want to split the date and time values

 time :     10:06:53
  Date      2019-08-06

Please provide the deceleration and implementation part


Solution

  • Declaration part:

     dtDateAndTime     : DATE_AND_TIME;
     sDateAndTime      : STRING;
     sDate             : STRING;
     sTime             : STRING;
    

    Implementation part:

    sDateAndTime := DT_TO_STRING(dtDateAndTime);
    sDate := MID(sDateAndTime, 10 , 4);
    sTime := RIGHT(sDateAndTime, 8);