Click to See Complete Forum and Search --> : Converting Whole Number In Sec To Time Format
Eric M
Jan 25th, 2000, 08:08 AM
How would you convert a whole number in seconds like 2525353 to be in the hh:mm:ss format? I have tried using format and it doesnt convert it correctly any help?
Lyla
Jan 25th, 2000, 10:48 AM
Hi.
In VB, You can't. You have to write your own function.
Hint, Try:
/ To divide by 60 .
\ To divide by 60 and get Integer results only.
MOD To get the remainder Only after dividing by 60 .
If more help needed let me know.
[This message has been edited by Lyla (edited 01-25-2000).]
[This message has been edited by Lyla (edited 01-25-2000).]
steviep
Jan 25th, 2000, 04:56 PM
The way I've done it is like this
Declare a variable at the top (option explicit say:
dim strMillisecs as string
dim strTime as string
I tend to use strings as integers sometimes crop the numbers
then create your own function like so:
Private Sub time_convert()
On Error Resume Next
dim hh as string
dim mm as string
dim ss as string
dim tt as string
If strMillisecs = "" Then Exit Sub
''10ths
tt = Right(strMillisecs, 3)
'hours
hh = Int(Val(strMillisecs / 1000) / 3600)
'mins
mm = Int(Int(strMillisecs / 1000) / 60) - (Val(hh) * 60)
'secs
ss = Int(strMillisecs / 1000) - (Val(mm) * 60) - (Val(hh) * 3600)
' this makes sure you get 01 instead of 1
If Len(hh) = 1 Then hh = "0" & hh
If Len(mm) = 1 Then mm = "0" & mm
If Len(ss) = 1 Then ss = "0" & ss
'this puts them all together
strTime = hh & ":" & mm & ":" & ss & "." & tt
End Sub
Then you can call it like so(maybe from a timer):
strMillisecs = mmcontrol1.position (or whatever)
time_convert
lblTimeThing = strTime
Hope this is of some use to you!
[This message has been edited by steviep (edited 01-26-2000).]
Lyla
Jan 25th, 2000, 07:34 PM
Hi. It's me again.
I haven't tested it yet, but try it.
Totalseconds=2525353
HH= Int(Totalseconds/3600) => 701
MM= Int(((Totalseconds/3600)-HH)*60) => 29
SS= Int(((((Totalseconds/3600)-HH)*60)-MM)*60) => 12
Msgbox HH & ":" & MM & ":" & SS
should be: 701:29:12
Good Luck
Try:
CDate(2525353 / 60& / 60& / 24&)
Then you could use the Format function to Format the output into anything(ok not anything :)) you want.
------------------
Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.