Results 1 to 7 of 7

Thread: Minutes into Hour

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288

    Minutes into Hour

    Is there any predefined function which I can use to convert minutes into hours?
    75 minutes should be 01:15
    20 minutes should be 00:20

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here you go:
    VB Code:
    1. Public Function GetFormatTime(p_lngMinutes As Long) As String
    2.     Dim strHour As String
    3.     Dim strMinutes As String
    4.    
    5.     strHour = Format(p_lngMinutes / 60, "00")
    6.     strMinutes = Format(p_lngMinutes Mod 60, "00")
    7.    
    8.     GetFormatTime = strHour & ":" & strMinutes
    9. End Function
    Then call it like this:

    MsgBox GetFormatTime(75)

  3. #3
    Lively Member sjwesley's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    73
    Try this

    Code:
    Private Sub Command1_Click()
        Dim d As Date
        d = Date
        d = DateAdd("n", 75, d)
        Debug.Print Format(d, "hh:mm")
    End Sub

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Serge, your code has some problems. Try converting 20.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    sjwesley
    Your code returns the same output always

  6. #6
    Tygur
    Guest
    Here's a function:
    VB Code:
    1. Function GetHoursMinutes(ByVal lMinutes As Long) As String
    2. Dim lHours As Long
    3. lHours = lMinutes \ 60
    4. lMinutes = lMinutes Mod 60
    5. GetHoursMinutes = Format(lHours, "0#") & ":" & Format(lMinutes, "0#")
    6. End Function

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Oops, typo.....I had Format(strHour & ":" & strMinutes). I cant use format because Format recognizes a valid date/time.

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