Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Convert Duration field into Hours and Minutes

Alon Grod
Tera Expert

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 

 

 

2 REPLIES 2

Dr Atul G- LNG
Tera Patron

Hi @Alon Grod 

 

https://www.servicenow.com/community/developer-forum/how-to-convert-duration-field-days-hours-minute...

 

https://www.servicenow.com/community/developer-forum/convert-duration-into-minute/m-p/1482599

 

*************************************************************************************************************
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/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Sohail Khilji
Kilo Patron

@Alon Grod , 

 

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

LinkedIn - Lets Connect