Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting seconds into hours minutes and seconds

Status
Not open for further replies.

jwpward

Programmer
Sep 5, 2003
45
GB
Hi

I'm displaying an online report using asp and one of the columns in my display table is 'call time' (it's for a call centre). This is being passed in in seconds from a stored procedure, so i need to convert it at the other end into hours minutes and seconds.
Is there an easy way to do this in javascript?

Thanks
 

Yup...

timeInSeconds = 4567;
hours = parseInt(timeInSeconds / 3600);
mins = parseInt((timeInSeconds - (hours * 3600)) / 60);
secs = timeInSeconds - (hours * 3600) - (mins * 60);

hours should be 1, mins should be 16, secs should be 7

Hope this helps,

Dan
 

Hehe - just realised I never tested it with:

1. A value below 3600 hour, and
2. A value below 60

SO you might want to try it with, for example, 3000 and 50 just to see if it still works ;o)

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top