Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

 

*************************************************************************************************************
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]

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

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