In STEP 7 (TIA Portal), how do you convert the number of milliseconds into days, hours, minutes and seconds?
In some applications in automation technology the total number of milliseconds is often used. The function block "MillisecToTime" takes the specified milliseconds and calculates the number of days, hours, minutes and seconds.
The example below shows the call of the function block "MillisecToTime" in the OB "ChangeTime" with parameterization of the variable from the data block "MsToTime".
The table below shows the input and output parameters with the data types and value ranges of the function block "MillisecToTime". After entering the number of milliseconds via the input parameter "milliSeconds" the calculated values are output via the output parameters "days", "hours", "minutes" and "seconds".
|milliSeconds||Input||DInt||Input of the milliseconds||0, ..., 2147483647|
|days||Output||Int||Number of calculated days||0, ..., 32767|
|hours||Output||Int||Number of calculated hours||0, ..., 23|
|minutes||Output||Int||Number of calculated minutes||0, ..., 59|
|seconds||Output||Int||Number of calculated seconds||0, ..., 59|
You can use the library for the S7-1200/S7-1500 and for the S7-300. The Master Copies folder contains two subfolders. Each subfolder contains the FB "MillisecToTime" with its instance DB, the global DB "MsToTime" and the OB "ChangeTime".
- If you are using the S7-1200 or S7-1500, you drag-and-drop the blocks from the subfolder "S7-1200/S7-1500" to the program folder.
- If you are using S7-300, you drag-and-drop the blocks from the subfolder "S7-300" to the program folder.
The FB "MillisecToTime" was created in the SCL programming language and contains comments in German and English.
The attached STEP 7 (TIA Portal) library contains the blocks described above. Unpack the file in a separate directory on your hard disk. Then you can use STEP 7 (TIA Portal) to open and edit the library.
You can only open and edit the library in STEP 7 (TIA Portal). Further information about opening libraries is available in Entry ID: 37364723.
More information about the conversion of day, hours, minutes and seconds into milliseconds is available in Entry ID: 43184859.
Fig. 1 and the download in this FAQ response were created with STEP 7 (TIA Portal) V15.