473,508 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Total Hour Duration Query

Hello

Have a bit of a problem, im trying to get the total number of
hours:minutes for all actions over the month in a query, have tried
two methods to no luck...
Duration This Month:
Format(Sum([tblIssues].[timeOff]-[tblIssues].[timeON]),"hh:nn")
displays the total hours but rolls over anything over 1 day and starts
over from 0 again

Duration This Month: CDate(Sum(tblIssues.timeOff-tblIssues.timeON))
displays it as the following if over 24 hours, ie for 32 hours would
display: 31/12/1899 08:00:00

Is there a way of totalling up the hours and displaying it in a
readable way within a query? The timeOn and timeOff are time fields
only as nothing would roll over 24 hours per instance although the
total in the month would exceed this.

Thanks for any advice.

Stephen
Nov 13 '05 #1
4 5690
Stephen,

First: you will have to be sure that timeOff is in the same day as timeON.
In your query you simply set as criterion: timeOff >= timeOn
Second: Try a third calculation-method.
Calculate the timedifference in *minutes*, add these minutes and then recalculate the
hours.

Check out the DateDiff function in the Help for this.
Minutes=Datediff("n",[timeON],[timeOff])
e.g. Sum in Minutes is 2356 then your number of hours is 2356 \60 and your Minutes left
will be 2356 mod 60.
This will be 39 hours and 16 minutes

--
Hope this helps
Arno R
"Stephen Young" <st***********@cwcom.co.uk> schreef in bericht
news:32**************************@posting.google.c om...
Hello

Have a bit of a problem, im trying to get the total number of
hours:minutes for all actions over the month in a query, have tried
two methods to no luck...
Duration This Month:
Format(Sum([tblIssues].[timeOff]-[tblIssues].[timeON]),"hh:nn")
displays the total hours but rolls over anything over 1 day and starts
over from 0 again

Duration This Month: CDate(Sum(tblIssues.timeOff-tblIssues.timeON))
displays it as the following if over 24 hours, ie for 32 hours would
display: 31/12/1899 08:00:00

Is there a way of totalling up the hours and displaying it in a
readable way within a query? The timeOn and timeOff are time fields
only as nothing would roll over 24 hours per instance although the
total in the month would exceed this.

Thanks for any advice.

Stephen


Nov 13 '05 #2
Thanks for the reply, managed to get it working using what you
suggested and the final expression in the query is

Duration This Month:
Sum(DateDiff("h",[tblExceptions].[timeOn],[tblExceptions].[timeOff])) &
":" &
Sum(DateDiff("n",[tblExceptions].[timeOn],[tblExceptions].[timeOff])
Mod 60)

which shows the time and is roughly accurate however for a four minute
duration it would show 0:4 and im not able to sort by duration, is
there a way to show it neatly as HH:MM and let access recognise this as
a time but display hour totals greater than 23:59

Nov 13 '05 #3
I handled this problem by creating a function that takes the difference
in seconds between two times and formats the result.
Your expression would become
Sec2Dur(Sum(DateDiff("s",[tblExceptions].[timeOn],[tblExceptions].[t*imeOff])))
Public Function Sec2Dur(seconds As Long) As String
'Converts seconds to hhhhh:mm:ss format
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
Good luck

Nov 13 '05 #4
Stephen,

As I said: "Calculate the timedifference in *minutes*, add these minutes and then
recalculate the hours."

What you do is unfortunately NOT correct ...
When the Sum of the minutes you count this way exceeds 60 then what ?

*First* you need to calculate and sum the minutes. *After* you format to hours and
minutes.
I understand you want to add the timedifference of several records?
Call a field TimeDiffInMinutes. TimeDiffInMinutes:
DateDiff("n",[tblExceptions].[timeOn],[tblExceptions].[timeOff])
Make a GroupBy query and Sum this field.

For display you can use a second query based on the first where you can do:
Duration This Month: CDate(TimeDiffInMinutes\60 & ":" & TimeDiffInMinutes mod 60)
This way you can also sort on TimeDiffInMinutes, which is what you say you want.

--
Hope this helps
Arno R
"Stephen" <st***********@cwcom.co.uk> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com...
Thanks for the reply, managed to get it working using what you
suggested and the final expression in the query is

Duration This Month:
Sum(DateDiff("h",[tblExceptions].[timeOn],[tblExceptions].[timeOff])) &
":" &
Sum(DateDiff("n",[tblExceptions].[timeOn],[tblExceptions].[timeOff])
Mod 60)

which shows the time and is roughly accurate however for a four minute
duration it would show 0:4 and im not able to sort by duration, is
there a way to show it neatly as HH:MM and let access recognise this as
a time but display hour totals greater than 23:59

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2023
by: MX1 | last post by:
I have query2 that sums a set of fields from query1. Works fine. However, when I try to add two of the calculated fields from query2, I get prompted for the label I gave the fields. I just hit...
2
2922
by: Gran | last post by:
Hi, Im using Access 97, and I have two subforms which have a total for the query'd data. I then go and total the two together on the main form. But, when one has no data it brings up an error. I...
8
1734
by: Yisroel Markov | last post by:
I have the following in my code: strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, " _ & " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions " _ & "INNER JOIN...
2
35861
by: mhodkin | last post by:
I created a query in which I have grouped data by City. I wish to calculate the percent of each value, e.g. City/(Total count of all Cities), in tbe next column of the query. I can't seem to...
5
7345
by: elitecodex | last post by:
Hey everyone. I have this query select * from `TableName` where `SomeIDField` 0 I can open a mysql command prompt and execute this command with no issues. However, Im trying to issue the...
5
13233
by: bill1313 | last post by:
I'm currently working on a component tracking file and we are using an hour meter query to always have up to date information. My problem is that I need the hour meter query to display the reading of...
1
2783
mangat
by: mangat | last post by:
Hi guy's i'm stuck in a similar problem. The problem is that i have two fields one shows the LogIn time of the user and other shows the Duration since the user LogIn and now i want to store the...
1
1408
by: midnightoil | last post by:
First, thanks for having a look at this post. I am trying to create a query that shows decrementing account balances. It reads the following fields from my tbl/Activity table: Customer ID, Week...
0
3141
by: Alagas | last post by:
Hi, I'm new to access 2003 & would like to know how to create a report that shows the grand total of counts, details are as the following: 1) I've a database of credit cards where I would like to...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.