Convert Duration field into Hours and Minutes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 06:55 AM
Hi,
i have the field u_duration of type duration.
I need to populate a the field u_time of type String with the hours and the minutes from the duration field using on update Business Rule.
For example,
Duration: 02:24:30. (Days: Hours: Minutes )
Time: 72:30 (Hours:Minutes)
The answer should always be Hours:Minutes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:02 AM
Hi @Alon Grod
https://www.servicenow.com/community/developer-forum/convert-duration-into-minute/m-p/1482599
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:03 AM
Try this,
var inputTime = "02:24:30"; //example
var timeComponents = inputTime.split(':');
var days = parseInt(timeComponents[0]);
var hours = parseInt(timeComponents[1]);
var minutes = parseInt(timeComponents[2]);
var totalHours = days * 24 + hours;
var outputTime = "Time: " + totalHours + ":" + minutes + " (Hours:Minutes)";
gs.info(outputTime);
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....