Solved

Second to hours and minutes

Posted on 2004-08-28
3
250 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:DARKSAGES
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 500 total points
ID: 11922518
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 Comment

by:DARKSAGES
ID: 11922797
Thanx, for the quick answer. That was really easy but i have something due really soon and i cant think straight.
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11922823
You're welcome

Darko
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question