I have a var that holdes a number of seconds. I would like to convert that into minutes and seconds...
EX: myVar = 255 seconds... I would like to do an MSGBOX where the result would be: 4 minutes and 15 seconds...
any ideas?
thanks
Printable View
I have a var that holdes a number of seconds. I would like to convert that into minutes and seconds...
EX: myVar = 255 seconds... I would like to do an MSGBOX where the result would be: 4 minutes and 15 seconds...
any ideas?
thanks
VB Code:
Dim minsec As String minsec = CStr(myVar) \ 60 & ":" & CStr(myVar Mod 60) MsgBox minsec
Here is a small function that I have used to do this:
Granted it doesn't go to days, but if you need that, I'm sure you can get it modified to do what you want.VB Code:
Public Function ConvertSeconds(ByVal sngSeconds As Single) As String Dim intHours As Integer Dim intMinutes As Integer Dim intSeconds As Integer Dim strOutString As String intHours = sngSeconds \ (60 * 60) intMinutes = (sngSeconds \ 60) - (intHours * 60) intSeconds = sngSeconds Mod 60 strOutString = "" If intHours <> 0 Then If intHours = 1 Then strOutString = intHours & " hour, " Else strOutString = intHours & " hours, " End If End If If intMinutes <> 0 Then If intMinutes = 1 Then strOutString = strOutString & intMinutes & " minute, " Else strOutString = strOutString & intMinutes & " minutes, " End If End If If intSeconds <> 0 Then If intSeconds = 1 Then strOutString = strOutString & intSeconds & " second." Else strOutString = strOutString & intSeconds & " seconds." End If End If If Len(strOutString) <= 0 Then 'Less than a second. strOutString = "1 second." End If ConvertSeconds = strOutString End Function
Edit: I just noticed this code will leave a , at the end if it's zero seconds, easy enough to fix if you want though.
Hope this helps.
Michael
thank you :)