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
Printable View
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
Here you go:
Then call it like this:VB Code:
Public Function GetFormatTime(p_lngMinutes As Long) As String Dim strHour As String Dim strMinutes As String strHour = Format(p_lngMinutes / 60, "00") strMinutes = Format(p_lngMinutes Mod 60, "00") GetFormatTime = strHour & ":" & strMinutes End Function
MsgBox GetFormatTime(75)
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
Serge, your code has some problems. Try converting 20.
sjwesley
Your code returns the same output always
Here's a function:
VB Code:
Function GetHoursMinutes(ByVal lMinutes As Long) As String Dim lHours As Long lHours = lMinutes \ 60 lMinutes = lMinutes Mod 60 GetHoursMinutes = Format(lHours, "0#") & ":" & Format(lMinutes, "0#") End Function
Oops, typo.....I had Format(strHour & ":" & strMinutes). I cant use format because Format recognizes a valid date/time.