|
-
Mar 4th, 2003, 01:54 PM
#1
Thread Starter
Hyperactive Member
converting seconds to minutes/seconds
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
-
Mar 4th, 2003, 01:57 PM
#2
Fanatic Member
VB Code:
Dim minsec As String
minsec = CStr(myVar) \ 60 & ":" & CStr(myVar Mod 60)
MsgBox minsec
-
Mar 4th, 2003, 01:58 PM
#3
Addicted Member
Here is a small function that I have used to do this:
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
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.
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
Last edited by Michael Woolsey; Mar 4th, 2003 at 02:01 PM.
Application/Web Developer
Visual Basic 6.0 SP5
Active Server Pages
Oracle 9i
- I'm going to live forever, or die trying!
-
Mar 4th, 2003, 02:11 PM
#4
Thread Starter
Hyperactive Member
thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|