Converting seconds into Days, hours, min, sec

# Thread: Converting seconds into Days, hours, min, sec

1. Zach Richards Guest

## Converting seconds into Days, hours, min, sec

Anyone know of a way in VBScript that will take an variable that contains an the number of seconds, and convert that into a format like this:<BR>Days, Hours, Minutes, Seconds<BR><BR>Even an algorithm would be nice if VBScript does not contain a function to do so<BR><BR>Thanks in advance!<BR><BR>Zach Richards<BR>zach@smokedog.com<BR>

2. Sateesh Guest

## RE: Converting seconds into Days, hours, min, sec

I dont think there is a method to calculate so, but i can suggest a logic it might be usefull for u in building a vbscript function.<BR>get the seconds (eg 1000000)<BR>to convert into min divide by 60 (16666.6666666666666666)<BR>check the value and if it is more than 60 than divide ity again by 60 to get the number or hrs (277.7777777777....)<BR>check the value and if it is greater than 24 divide the value by 24 to get the number of days (11.57407040.....) once you get the number of days split the days seperatly using the split keyword finding for the period(.) on the result (.5740704...) this will give you the fractional day value multiply that by 24 (13.77777777....) using the split again split the numbers of hrs and mulitiply the fractional value (.77777777777) again by 60 to get the minutes remaining (46.6666666666666) again split the value and multiply the remaining fractional (.666666.....) value with 60 to get the seconds remaining (40), once you got the all thse values you can very well club those like<BR>11 days, 13 hrs 46 minutes and 40 seconds.<BR>The logic should be something like this, i hope this will work, even there might be some logic which is quite simpler than this, try your best.

3. Junior Member
Join Date
Dec 1969
Posts
9

## RE: Converting seconds into Days, hours, min, sec

I made this for a VB prog that had a time in seconds and needed it converted to hours, minutes and seconds, this is what I got, take the Modulus (whats left in a integer division) of the total seconds, then you get the seconds. Divide the total seconds by 60 so you get minutes and take the modulus of that to get the minutes, now divide the total minutes (former seconds) with 60 to get the hours.. remember, only INTEGER division, no decimals in the division, the modulus thingie takes care of the rest..<BR>Of course you could go on and modulus the hours with 24 too, and divide by 24 to get the days, but I haven&#039t got that in my code.. Heh, as you notice my english sucks since I&#039m just 15 and from sweden.. anyways, I talk too much, try this code..<BR><BR>iTimeinseconds is the time in seconds that you want to split up hours, minutes and seconds, iSeconds is the seconds, iMins is the minutes and can you guess what iHours is?<BR><BR> iSeconds = iTimeinseconds Mod 60<BR> iTimeinseconds = iTimeinseconds / 60<BR> <BR> iMins = iTimeinseconds Mod 60<BR> iTimeinseconds = iTimeinseconds / 60<BR> <BR> iHours = iTimeinseconds<BR><BR>Now, it was a while ago I wrote this, I haven&#039t tried it so I can&#039t GUARANTEE it works, but it should get you on the right track if you&#039re lost :)<BR><BR>Good Luck and Happy Programming!<BR><BR>-JobE

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•