Results 1 to 5 of 5

Thread: Converting Whole Number In Sec To Time Format

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    14

    Post

    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?

  2. #2
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Post

    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).]

  3. #3
    Member
    Join Date
    Sep 1999
    Location
    UK
    Posts
    45

    Post

    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).]

  4. #4
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Post

    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

  5. #5
    Guest

    Post

    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: [email protected]
    ICQ: 15440110
    Homepage: http://www.azzmodan.demon.nl




Posting Permissions

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



Click Here to Expand Forum to Full Width