Results 1 to 7 of 7

Thread: [RESOLVED] Convert HH:MM into seconds

  1. #1

    Thread Starter
    Junior Member simonwinsor's Avatar
    Join Date
    Apr 2008
    Location
    USA
    Posts
    22

    Resolved [RESOLVED] Convert HH:MM into seconds

    Hey Folks,

    I have 2 values that i have extracted from a website in 2 textboxs.

    text1 = 7:6
    text2 = 7:06:33

    is there any ways in VB6 to convert them into Seconds ?

    text3 = 25560
    test4 = 25593

    ?? have been trying to code it since past 2 weeks but no luck with the status as n00b cant do much too


    Please anyone

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Convert HH:MM into seconds

    Convert it to datetime data type using CDATE() or TimeSerial() functions then get number of seconds elapsed using DateDiff() function.

    msgbox datediff("s", 0, time) 'sample using built in function time that returns current time

    Please take note of the duration you are testing as dates are represented internally as numbers with the whole number portion as the number of days and the decimal portion the part of a day, e.g. half a day is 0.5.

    msgbox datediff("s", 0, now) 'seconds since min date supported
    msgbox datediff("s", date, now) 'seconds since midnight

  3. #3
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Convert HH:MM into seconds

    Code:
        dim MyDate as Date
        dim X as long
    
        MyDate = cdate(text1.text)
        X = (datepart("h",MyDate) * 3600) + (datepart("n",MyDate) * 60) + datepart("s",MyDate)

  4. #4

    Thread Starter
    Junior Member simonwinsor's Avatar
    Join Date
    Apr 2008
    Location
    USA
    Posts
    22

    Re: Convert HH:MM into seconds

    thanks a lot for your time leinad31 & longwolf

    with the correct terms i must walk the correct path.

    let me try and get back to ya all



  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Convert HH:MM into seconds

    Another way:
    Code:
    s = CDate(Text1.Text) * 86400 '-- 24*60*60 = 86400
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Convert HH:MM into seconds

    Quote Originally Posted by anhn
    Another way:
    Code:
    s = CDate(Text1.Text) * 86400 '-- 24*60*60 = 86400
    Coool!!!

  7. #7

    Thread Starter
    Junior Member simonwinsor's Avatar
    Join Date
    Apr 2008
    Location
    USA
    Posts
    22

    Re: Convert HH:MM into seconds

    Final Code

    put this on a button with 2 text box.

    Code:
    Dim MyDate As Date
        Dim X As Long
    
        MyDate = CDate(Text1.Text)
        X = (DatePart("h", MyDate) * 3600) + (DatePart("n", MyDate) * 60) + DatePart("s", MyDate)
        Text2.Text = X
    Is this the fasted Resolved thread on the forum

    Super thanks to all ..you really made my day


    Simon

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