IECStringUtils.FormatDateTime

lukas
2022-05-30
2025-10-07
  • lukas - 2022-05-30

    Hello all,
    there is lib IECStringUtils in Codesys that contains FormatDateTime function.

    It works just fine.

    sFormat := '%t[HH:mm:ss  dd. MM. yyyy]';
    sTime := DWORD_TO_STRING(dwTimeDateLocal);
    xFormatDateTimeOK := FormatDateTime(cbpResult := ADR(sTime), uiResultCapacity := SIZEOF(sTime), cbpFormat := ADR(sFormat));
    

    sTime then contains 16:40:00 30. 05. 2022, so exactly what i wanted.

    But, when I set in Visualization Manager - General Settings - checkbox Use unicodestrings, this function returns in sTime undecoded number. Is this a bug?

    I know I can use '%t[HH:mm:ss dd. MM. yyyy]' directly in visu (it works ok in there), but I need date and time string for creating a filename.

    xFormatDateTimeOK is still FALSE (with or without "Use unicodestring" checked) - bug as well or i'm missing something?

    Thanks for reply, Lukas.

     
  • bnewman - 2025-07-25

    Update as of 2025:

    This function (IECStringUtils.FormatDateTime) doesn't make any sense there isn't any parameter that accepts a Date_Time value.

    I have no idea what's purpose even is.

    I am going to use StuSprintf from the StringUtils library for this purpose.

     
  • TimvH

    TimvH - 2025-07-29

    There has been a fix in SP21. I tried it in this version with the option "Use unicodestring" enabled in the Visualization Manager and it worked if the variables used for the function are declared as WSTRING variables

        wsFormat : WSTRING := "%t[HH:mm:ss  dd.MM.yyyy]";
        wsTime : WSTRING;
    
    IECStringUtils.FormatDateTime(cbpResult := ADR(wsTime), uiResultCapacity := SIZEOF(wsTime), cbpFormat := ADR(wsFormat));
    
     
  • hteich - 2025-10-07

    Does that actually work, though? Where do you put in the actual Date_Time value??

     

Log in to post a comment.