Results 1 to 3 of 3

Thread: Integer to Time

  1. #1
    Join Date
    Aug 2002
    Arlington, TX

    Unanswered: Integer to Time

    I've tried to use Access's built in functions for this but they do not work. I have an integer ranging from 1 digit (0) to 4 digits (2400). I need to be able to convert this to military time. Any suggestions?

  2. #2
    Join Date
    Aug 2002
    Québec, Canada
    It depends on when you have to change the time, if you can use a function, I suggest you use the following code in a module, change it a bit to accept a integer as parameter and to return a date type:

        'The date variable
        Dim SomeDate As Date
        'Hour, min and second
        Dim strHour As String
        Dim strMinute As String
        Dim strSecond As String
        'The time you have as an integer
        Dim intTimeInNumber As Integer
        'The same time but formatted in string
        Dim intTimeInString As String
        'Suppose, 0230, 2h30
        intTimeInNumber = 230
        'Change 230 to "0230"
        intTimeInString = Format(intTimeInNumber, "0000")
        'Just to follow the steps
        MsgBox intTimeInString
        'Extract hour and minute, second, on a 4 digit, are 00
        strHour = Left$(intTimeInString, 2)
        strMinute = Right$(intTimeInString, 2)
        strSecond = "00"
        'Still to follow the program
        MsgBox "HOUR: " & strHour & vbCrLf & "MIN:" & strMinute
        'Automatic conversion to Date format, you can also use Format() function
        'Format used "##:##:##"
        SomeDate = strHour & ":" & strMinute & ":" & "00"
        'Show the time (time and date are the same variable, a
        'only time variable is a date variable Without date )
        MsgBox SomeDate
    JefB - hope it helps

  3. #3
    Join Date
    Aug 2002
    Arlington, TX
    had to make some adjustments but that code worked great
    thanks for your help
    i guess i was just making it harder then it actually was
    was tryin to split the integer into an array etc

    well thanks agin bud

Posting Permissions

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