converting text to Hours Minutes and Seconds

have a database which has three fields for Hours Minutes and seconds these are just numbers and have no relation to time.

I need in a report,code that will convert the numbers to time and add the seconds to minutes and add the minutes to hours.

Thanks

Bartley




Answer this question

converting text to Hours Minutes and Seconds

  • Dhaval4friends

    Hi Bartley

    If hours, minutes and seconds are stored as intergers in your db you could put a function in a module to do the conversion e.g.

    Public Function TimeFormat(Hr As Integer, Mn As Integer, Sec As Integer) As String
    If Hr < 10 Then TimeFormat = "0" & Trim$(Str$(Hr)) Else TimeFormat = Trim$(Str$(Hr))
    If Mn < 10 Then TimeFormat = TimeFormat & ":0" & Trim$(Str$(Mn)) Else TimeFormat = TimeFormat & ":" & Trim$(Str$(Mn))
    If Sec < 10 Then TimeFormat = TimeFormat & ":0" & Trim$(Str$(Sec)) Else TimeFormat = TimeFormat & ":" & Trim$(Str$(Sec))
    End Function

    You then use the function in your query or report passing the three fileds as parameters


  • Danca

    Hi Bartley

    you can use functions in your report. You can add a user function to a module and use it in reports, queries, forms etc. I suggest you use the example Derek posted converting it to a function which takes three parameters. Then on you report place an unbound field, which you can then use the build option to select your function, and to put in each of your three fileds as parameters.

    Regards

    ADG


  • Vadivel

    Thanks for your reply

    I am having problems with the code as to where exactly it should be inserted.

    What I am trying to do is to run a report showing each a/c no and each a/c numbers total time elapsed

    The three fields are separate Hrs Min and Sec

    Thanks

    Bartley



  • Siteadm

    Hi,

    You could use the date method DateAdd to add the seconds, minutes and hours.

    Public Sub ReturnDate()
        Dim myDate As Date
        myDate = CDate("00:00:00")
       
        'add seconds
        myDate = DateAdd("s", "65", myDate)
        'add minutes
        myDate = DateAdd("n", "125", myDate)
        'add hours
        myDate = DateAdd("h", "5", myDate)

        MsgBox myDate
    End Sub

     



  • converting text to Hours Minutes and Seconds