Formatting date and time in HMI
I need to display time using format HH24:MM:SS.
I use system variables RTC.HOURS, RTC.MINUTES and RTC.SECONDS. But when I display them in HMI, I see only one digit when corresponding value is below 10. How to add this leading zero, i.e. display 08 when the value is 8?
Now I added static text 0 and display condition of it when the value is below 10, but this is definitely not the cleanest solution 🙂
Comments
Hello!
The most common one-line way to display date&time in IEC 61131-3 format is to use RTC_S fb.
Also very usefull will be using of TO_STRING conversion with {format string}.
HMI_string_var := TO_STRING( LDATE_AND_TIME, '{0:dd-MM-yyyy HH:mm:ss}');
You can find out additional info in IDE build-in help center.
Time-oriented FB's you can find in PLCNextBase library from the Store.
Best regards.
Thank you. TO_STRING helped to solve the issue: