Skip to content

Displaying timers without milliseconds

I'm currently displaying some timers that include milliseconds, but I find this unnecessary and it makes the display a bit cluttered. I'd like to show the timers without the milliseconds. The data type is 'TIME', derived from a TON timer.


Here's an example that returns: T#59m45.200s:

StringCountDownTimer := CONCAT('Count Down Timer Shutdown [', CONCAT(TO_STRING(CountDownTimerShutdown, '{0}'), ']'));

I'd be happy with T#59m45s or 59:45.


I've consulted the PLCnextHelp Engineer documentation and tried the following formats, tried both with and without the tailing s:

- T#{0:hh}:{0:mm}:{0:ss}s

- {0:hh}:{0:mm}:{0:ss}s



However, both attempts result in displaying empty brackets: [].

Does anyone have any suggestions on how to achieve the desired format without milliseconds? Any help would be appreciated!

Comments

  • edited May 2024

    Hello!

    You are a little bit missed with documentation line. And as a result give wrong formatting string to function, as a result receive empty brackets...

    All you need is in TO_STRING help page, FORMAT STRING / Date and Time format specifiers.... And format string '{0:hh:mm:ss}' or '[{0:hh:mm:ss}]', to reduce CONCAT usage.

    BR

  • Hello Oleksandr,

    Thank you for your suggestion. I did try using the format specifier {0:hh:mm:ss}, but unfortunately, it didn’t work in my case.

    Just to clarify, I’m not attempting to display standard clock time. Instead, I’m looking to display a countdown timer with the format:

    MaintAlarmStringCountDownTimer := CONCAT('Maintenance - Alarms Suppressed [', CONCAT(TO_STRING(CountDownTimerShutdown, '{0:hh:mm:ss}'), ']')); 
    

    Coming from:

     CountDownTimerShutdown := ShutdownTimer.PT - ShutdownTimer.ET;

    This is intended to visually indicate that maintenance is active, and therefore some alarms are suppressed, with a maximum time of one hour. However, the result I'm getting with the format you suggested still leads to empty brackets: Maintenance - Alarms Suppressed [].

    I wonder if there might be a specific issue with how the TO_STRING function handles the TIME datatype in this context. Any further insights or suggestions you might have would be greatly appreciated!

    Best regards,

    Michel

  • edited May 2024

    Hmmm...

    It seems you are right, and there is no appropriating format string for TIME process in manner you expect....

    In this case additional process of string result will be necessary.


  • Michel:

    I attempted to set up your problem -- I simplified it to just be a timer (instead of countdown timer); I got the same results as you...there is no output from the To_String function with the '{0:hh:mm:ss}' format.

    Out of curiosity, I used the same format string '{0:hh.mm.ss}' to a LDT variable (not just a TIME data type) and the output worked:

    One way around this might be to use the SPLIT_TIME function, convert the pieces to strings, and then CONCAT them. A little cumbersome but it works...


    SFW

  • An easy work around is to convert TIME to INT and divide by 1000 (conversion gives ms)

  • edited May 2024

    Thanks, everyone, for looking into this and offering suggestions. PLCnext Engineer keeps surprising me. I've decided to keep the milliseconds—it's not worth the hassle and workarounds to remove them from the (HMI) visible countdown timers.


    @fluxmodel About: "An easy workaround is to convert TIME to INT and divide by 1000 (conversion gives ms)":


    I'm not sure what you mean. The TO_INT function block doesn't accept the TIME data type as input. The function is available for the following input data types:

    - BOOL, BYTE, WORD, DWORD, LWORD

    - Integers: SINT, DINT, LINT, USINT, UINT, UDINT, ULINT

    - Floating point numbers: REAL, LREAL

    - STRING, WSTRING

  • Hi, actually TIME datatype consists 32bits OR DWORD, so it can be freely converted to DINT datatype, with TO_DINT().

    Other conversion could be provided like a chain of subsequent conversion functions calls, if necessary.

    BR.

  • edited May 2024


    Sorry about that, I meant DINT as INT is too small.


    edit: ninjaed by Oleks 😅

Sign In or Register to comment.