# Second to hours and minutes

i am currently using this code to show time in hours and minutes from seconds. (ttime = seconds) Every 60 seconds it i make it refresh itself. It works great, the only problem that i see with it is that sometimes when its about to change from hole hours. This is what happens. It displays 02:00 then it displays (60s after) 01:00 then (60s after) 01:59. Another example would be 01:00 then 00:00 then 00:59. How can i fix this? Vb6

h = Int(Val(ttime) / 3600)
m = Int((Val(ttime) / 60) Mod 60)
If h < 10 Then
h = "0" & h
End If
If m < 10 Then
m = "0" & m
End If
###### Who is Participating?

Commented:
Hi, try this (it also converts to days):

Dim seconds As Long
Dim d As Long 'days
Dim h As Long 'hours
Dim m As Long 'minutes
Dim s As Long 'seconds

seconds = 86401 'one day, zero hours and mins and one sec

If (seconds >= 86400) Then
d = seconds \ 86400
seconds = seconds Mod 86400
End If

If (seconds >= 3600) Then
h = seconds \ 3600
seconds = seconds Mod 3600
End If

If (seconds >= 60) Then
m = seconds \ 60
seconds = seconds Mod 60
End If
s = seconds

Darko
0

Author Commented:
Thanx, for the quick answer. That was really easy but i have something due really soon and i cant think straight.
0

Commented:
You're welcome

Darko
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.