×
Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 42637538, Entry date: 02/23/2016
(4)
Rate

In STEP 7 (TIA Portal), how do you convert the number of milliseconds into days, hours, minutes and seconds?

  • Entry
  • Associated product(s)
Using the FB "MillisecToTime" from the library included in the entry you can determine the days, hours, minutes and seconds from the number of milliseconds.

Description
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".


Fig. 1

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".

Parameter
Interface
Data type
Description
Value range
milliSecondsInputDIntInput of the milliseconds0, ..., 2147483647
daysOutputIntNumber of calculated days0, ..., 32767
hoursOutputIntNumber of calculated hours0, ..., 23
minutesOutputIntNumber of calculated minutes0, ..., 59
secondsOutputIntNumber of calculated seconds0, ..., 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.

Download
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.

 Registrierung notwendig  42637538_MillisecToTime_Lib_TIA_Portal_V15.zip (329,8 KB)

Note
You can only open and edit the library in STEP 7 (TIA Portal). Further information about opening libraries is available in Entry ID: 37364723.

Further Information
More information about the conversion of day, hours, minutes and seconds into milliseconds is available in Entry ID: 43184859.

Creation Environment
Fig. 1 and the download in this FAQ response were created with STEP 7 (TIA Portal) V15.

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.