Converting seconds to hh:mm:ss

C

cyb3rwolf

Hello.
I have a form that has 3 fields:
Stime (Start time)
Etime (End time)
Ttime (Total Time)

So far i have buttons on my form for "Start" and "Complete." When you click
"Start," it puts in the current date and time in Stime. When you click
complete, it puts in the current date and time in Etime. Then, it also
figures out how many seconds (as an integer) has elapsed bewteen Stime and
Etime and puts that in the Ttime field. What i'm trying to do is have
another field in my form that takes the seconds from Ttime, converts it to
hh:mm:ss format to be put in another field in the form; including if the
duration is over 24 hours. Anybody help me out? My coding so far for the
"complete" click event procedure:

Private Sub Command36_Click()
Dim totalminutes As Long
Dim interval As Variant
'Dim duration As String
Me.Etime = Now()
interval = Me.Etime - Me.Stime
totalseconds = Int(CSng(interval * 86400))
Me.Ttime = totalseconds
End Sub

So, i would need to take Me.Ttime, convert it to hh:mm:ss and then put in in
a different text box on my form
 
B

Bob Quintal

Hello.
I have a form that has 3 fields:
Stime (Start time)
Etime (End time)
Ttime (Total Time)

So far i have buttons on my form for "Start" and "Complete." When
you click "Start," it puts in the current date and time in Stime.
When you click complete, it puts in the current date and time in
Etime. Then, it also figures out how many seconds (as an integer)
has elapsed bewteen Stime and Etime and puts that in the Ttime
field. What i'm trying to do is have another field in my form
that takes the seconds from Ttime, converts it to hh:mm:ss format
to be put in another field in the form; including if the duration
is over 24 hours. Anybody help me out? My coding so far for the
"complete" click event procedure:

Private Sub Command36_Click()
Dim totalminutes As Long
Dim interval As Variant
'Dim duration As String
Me.Etime = Now()
interval = Me.Etime - Me.Stime
totalseconds = Int(CSng(interval * 86400))
Me.Ttime = totalseconds
End Sub

So, i would need to take Me.Ttime, convert it to hh:mm:ss and then
put in in a different text box on my form

Public Function sec2dur(seconds As Long) As String
On Error Resume Next

Dim hrs As Long
Dim mins As Integer
Dim secs As Integer

hrs = Int(seconds / 3600)
mins = Int((seconds - (3600 * hrs)) / 60)
secs = seconds - (hrs * 3600 + mins * 60)

sec2dur = Format(hrs, "#,##0") & ":" & Format(mins, "00") & ":" &
Format(secs, "00")

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top