UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Converting Seconds, Summing, Office 2007    
 
   
danbouton
post Apr 29 2010, 09:41 AM
Post #1

UtterAccess Enthusiast
Posts: 74
From: Indiana



I know this is another of those elementary things I am just missing.

In the detail section of my report I have a field [Duration]. Duration represents seconds.
In the report footer I have a the sum of Duration, or =Sum([Duration]).

I would like to add in the Detail section of the report an expression which will take [Duration] and convert it to hh/mm/ss.
I would like to add in the Report Footer section of the report an expression which will take my sum of [Duration] and convert it to hh/mm/ss.... keeping in mind, this may be over 24 hours.

Suggestions?
Go to the top of the page
 
+
 
Start new topic
Replies
rbianco
post Apr 29 2010, 10:26 AM
Post #2

UtterAccess VIP
Posts: 1,730
From: Carrollton, TX



I wanted the excercise and came up with this duration function:

CODE
Public Function MyDuration(MySeconds As Long) As String
Dim iHours As Long
Dim iMinutes As Integer
Dim iSeconds As Integer

iHours = Fix(MySeconds / 3600)
iMinutes = Fix((MySeconds - (iHours * 3600)) / 60)
iSeconds = (MySeconds - (iHours * 3600)) - (iMinutes * 60)

If iHours > 0 Then
    MyDuration = CStr(iHours) & ":"
Else
    MyDuration = "0:"
End If

If iMinutes > 0 Then
    MyDuration = MyDuration & Right("0" & CStr(iMinutes) & ":", 3)
Else
    MyDuration = MyDuration & "00:"
End If

If iSeconds > 0 Then
    MyDuration = MyDuration & Right("0" & CStr(iSeconds), 2)
Else
    MyDuration = MyDuration & "00"
End If
End Function
Go to the top of the page
 
+
danbouton
post Apr 29 2010, 12:28 PM
Post #3

UtterAccess Enthusiast
Posts: 74
From: Indiana



QUOTE (rbianco @ Apr 29 2010, 11:26 AM) *
I wanted the excercise and came up with this duration function:

CODE
Public Function MyDuration(MySeconds As Long) As String
Dim iHours As Long
Dim iMinutes As Integer
Dim iSeconds As Integer

iHours = Fix(MySeconds / 3600)
iMinutes = Fix((MySeconds - (iHours * 3600)) / 60)
iSeconds = (MySeconds - (iHours * 3600)) - (iMinutes * 60)

If iHours > 0 Then
    MyDuration = CStr(iHours) & ":"
Else
    MyDuration = "0:"
End If

If iMinutes > 0 Then
    MyDuration = MyDuration & Right("0" & CStr(iMinutes) & ":", 3)
Else
    MyDuration = MyDuration & "00:"
End If

If iSeconds > 0 Then
    MyDuration = MyDuration & Right("0" & CStr(iSeconds), 2)
Else
    MyDuration = MyDuration & "00"
End If
End Function


I used this one. Thank you to all. I created a module and named it Mod_MyDuration. This was a great find! Thank you. This piece of code is going in my collection.
Go to the top of the page
 
+

Posts in this topic


Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 26th May 2013 - 02:18 AM