# Ts\_To\_Datetimestr

**Ts\_To\_Datetimestr**\
Processes input number with specified '**unit**' (s, ms, ns, excel\_date) and converts the value to **datetime** string specified by '**format**',  default is ISO format. \
Input must be a float or int. \
@param '**unit' (**&#x54;ype string), must be s,ms,ns,excel\_date, default is '**ms**' \
@param '**format' (**&#x54;ype string), default is None (ISO format)\
\
This function is useful in case users want to convert to proper date-time strings.

### Example 1:&#x20;

Step 1: Create an empty **ts\_to\_datetimestr\_example\_1** using AIOps studio as shown in the below screenshot. 

![Empty pipeline](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MeSvY3KWBkG4SkKKuy_%2F-MeSxiM_Zn80c5_ROp8Z%2FScreen%20Shot%202021-07-12%20at%208.43.49%20PM.png?alt=media\&token=26f1d834-ca56-4d3d-b4ea-28ed84b98b5f)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a dataset row using current time in milliseconds.`*\
*`##### dm function ts_to_datetimestr is used to convert string data into proper`* \
*`##### date time string using ISO format (default). This function takes an additional`* \
*`##### parameter unit using 'ms', 's'.`* \
\
*`@dm:empty`* \
*`--> @dm:addrow Time_in_Milliseconds = '1626147743837'`*\
*`--> @dm:map to = 'Time_in_String' & from = 'Time_in_Milliseconds' & func = 'ts_to_datetimestr' & unit = 'ms'`* \
*`--> *dm:filter * get Time_in_String`*<br>

![Pipeline code added to empty pipeline created](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MeSzg0cl4bF_bs-oF8y%2F-MeT-MSuxfmvgmqCDrGS%2FScreen%20Shot%202021-07-12%20at%208.55.08%20PM.png?alt=media\&token=68823f2d-6b92-448e-94c2-a673150fcef6)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![Pipeline code is verified using 'Verify' button as shown above.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MeT-qQBU6yQCyNTU8fk%2F-MeT-wiBNax2-CGbVtvC%2FScreen%20Shot%202021-07-12%20at%208.58.00%20PM.png?alt=media\&token=18fde3fb-4726-4c69-ad30-32260aabc178)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Successful execution of pipeline without any errors](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MeT03RC_MlIEHtKXFEX%2F-MeT0MJTW-_gcw7fGSYh%2FScreen%20Shot%202021-07-12%20at%208.59.49%20PM.png?alt=media\&token=024ce865-2986-4346-b2f2-893791a9c874)

Step 5: RDA uses the dm function **ts\_to\_datetimestr** to convert milliseconds into readable string format using ISO format as shown below.\
\
&#x20;This function will be useful when the dataset contains timestamps in ms, s, excel\_date that need to be converted to string format for reporting purposes.

![Successful execution of pipeline using dm function 'ts\_to\_datetimestr' and prints output in string format](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MeT2e9cUKGC9Jq4oZsd%2F-MeT35G8ZadK-UeEksqO%2FScreen%20Shot%202021-07-12%20at%209.11.45%20PM.png?alt=media\&token=381d3d07-4189-40b8-bd6c-88d542c08788)
