Results 1 to 9 of 9

Thread: How to add to times??

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    How can I add to times in the following format:

    Ex.

    00:00:02 + 00:00:02 = 00:00:04

    ???
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Question

    Never mind, figured it out...I think...
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    If you figured it out, feel free to either share your knowledge (answer your own post ) or delete the thread by deleting the original post...
    ~seaweed

  4. #4
    Matthew Gates
    Guest
    He most likely used the DateAdd function.
    Don't know why they call it the DateAdd function when you can add times as well .

  5. #5
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    To add time convert it to the lowest common interval of time.

    I mean if all your data is hours and minutes convert to minutes sum the data, then convert back to hours and minutes.

    If data is hours minutes and seconds, convert to seconds sum the seconds then convert back.

    Here are a couple of conversion functions I have been working on that allow you to convert time values greater than 24 hrs to seconds and back again (Note where time> 24 hrs is involved none of the time/date functions work which is why I have avoided using them):

    Code:
    Function TimeToSeconds(ByVal Time As String) As Variant
     'by James Mayo
     'In: Time String In format hh:mm:ss
     'Out: Number of seconds Or "" If cannot calculate seconds
     
     Dim a As Variant
     Dim i&
     
     TimeToSeconds = ""
     a = Split(Time, ":", , vbTextCompare)
     For i = 0 To UBound(a)
        If Not IsNumeric(a(i)) Then
            TimeToSeconds = ""
            Exit Function
        Else
            a(i) = Fix(a(i)) 'only want Integer component
        End If
        
        Select Case i
            Case 0
                TimeToSeconds = a(i) * 3600 'hours
            Case 1
                TimeToSeconds = TimeToSeconds + a(i) * 60 'minutes
            Case 2
                TimeToSeconds = TimeToSeconds + a(i) 'seconds
            Case Else
                TimeToSeconds = ""
        End Select
    
     Next i
    
    End Function
    
    
    Function SecondsToTime(ByVal Seconds As Double) As String
     'by James Mayo
     'In: Seconds
     'Out: String hh:mm:ss Or "" If cannot calculate
     Dim Hours&, Minutes&
     
     SecondsToTime = ""
     If Seconds > 0 Then
        Seconds = Clng(Seconds) 'only interested In Integer component
        hours = Clng(Seconds / 3600)
        Seconds = Seconds - (hours * 3600)
        minutes = Clng(Seconds / 60)
        Seconds = Seconds - (minutes * 60)
        SecondsToTime = hours & ":" & minutes & ":" & Seconds
     End If
     End Function

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621
    but you could use the built in functions to isolate the individual parts. min(time) sec(time) etc.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  7. #7
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    I tried Lord Orwell, but this didn't work:

    Code:
    MsgBox Minute("25:01:01")

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621
    of course not. That's an illegal time. there are only 24 hours in a day, and it starts at zero.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  9. #9
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Perhaps I didn't get your point about using the built in functions to isolate the individual parts. Could you please ellaborate?

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