Convert Minutes into days:hrs:mins:secs format

Maheshwar1
Tera Contributor

Hi,

I am working on an integration for Monthly data trends.

Against an API request to get the Server Uptime value, I am getting result in minutes (80564.478 mins)

My requirement is to push this value in minutes after converting it into days:hours:minutes:seconds in the reporting table.

Can someone please advise how can I convert it into the required format

Regards,

Mahesh

1 ACCEPTED SOLUTION

Vamsi Sreenivas
Giga Guru

Hi Maheshwar,

 

You can simply use the GlideDuration API from ServiceNow as below: it takes milliseconds as input.

var gd = new GlideDuration(80564.478*60*1000); // time in milliseconds
var duration = gd.getDurationValue() + ''; // Output: 55 22:44:28
var finalDuration = duration.split(' ').join(':'); //. Output: 55:22:44:28

 

Mark my answer as HELPFUL / CORRECT if this help resolve your issue.

Regards,

Vamsi S

View solution in original post

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

Please try below in your script to convert minutes into Day, hours etc:

var time  = 80564.478;
   var result = Math.floor(time/24/60) + ":" + Math.floor(time/60%24) + ':' + Math.floor(time%60)+':'+Math.floor((time%60)%60);

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Vamsi Sreenivas
Giga Guru

Hi Maheshwar,

 

You can simply use the GlideDuration API from ServiceNow as below: it takes milliseconds as input.

var gd = new GlideDuration(80564.478*60*1000); // time in milliseconds
var duration = gd.getDurationValue() + ''; // Output: 55 22:44:28
var finalDuration = duration.split(' ').join(':'); //. Output: 55:22:44:28

 

Mark my answer as HELPFUL / CORRECT if this help resolve your issue.

Regards,

Vamsi S