How to convert second into hours ?

coolsaurabh
Tera Contributor

How can I concert time from second to hours ?

Example :- If seconds = 2403

                                      then hours = 2400/3600 = .6675

thanks,

Sourabh

1 ACCEPTED SOLUTION

Like this?



In Background scripts:



d = Number(2403);


var h = (d / 3600).toFixed(4);


gs.print(h);



I get:



[0:00:00.000] Script completed in scope global: script



*** Script: 0.6675

View solution in original post

3 REPLIES 3

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);


Hi Sergiu,



In above solution h,m,s provide duration in hours,minute and second separately. While I need duration in hours in decimal format.



Like



if seconds = 2403


                 


then hours = 2400/3600 = .6675



Thanks,


Sourabh


Like this?



In Background scripts:



d = Number(2403);


var h = (d / 3600).toFixed(4);


gs.print(h);



I get:



[0:00:00.000] Script completed in scope global: script



*** Script: 0.6675