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

Home Posts Topics Members FAQ

Sum() on time values

228 New Member
Hi,

I have a table with column finishtime. It can stores the time it took for a person to finish his task. it can range from 00:01:00 to 12:59:59 (company rule). The program works perfectly fine in all except when I need to find out the total time it took for a person to finish his task. Sum converts the time to AM/PM and returns time instead.

For instance, I have this two values: 12:58:36 and 12:10:10. The total time it took him is more than 25 hours and I need to return a time like 25:xx:xx.

But it returns :01:08:46

The query i am using is
Expand|Select|Wrap|Line Numbers
  1. SELECT format(Sum(CDate(finishtime)),'hh:nn:ss') AS ttltime FROM table1
  2.  
finishtime is a text field by the way. And it doesn't matter if I append AM/PM to the values. The result is the same.

Any tips please?
Oct 12 '10 #1
6 12863
NeoPa
32,557 Recognized Expert Moderator MVP
There is no format option that I'm aware of that will give you that functionality I'm afraid Sam. You'll have to roll your own. You know how date data is stored yes?
Oct 12 '10 #2
dsatino
393 Contributor
Your best best would be to convert everything to a single numerically formatted unit, probably hours.

So 12:58:36 becomes:

12+(58/60)+(36/3600)= 12.97667 Hours

And 12:10:10 becomes:

12+(10/60)+(10/3600)= 12.16944 Hours

Total Time = 25.14611 = 25:08:46

Since finishTime is a text field, it will be easy to capture the parts using a mid() function.
Oct 12 '10 #3
Mariostg
332 Contributor
Try this function:
Expand|Select|Wrap|Line Numbers
  1. Function AddTime()
  2.     Dim H As Long
  3.     Dim M As Long
  4.     Dim S As Long
  5.     Dim HMS As String
  6.     Dim t1inSecond As Long
  7.     Dim t2inSecond As Long
  8.     Dim st As Long
  9.     Dim tArray As Variant
  10.     Dim time1 As Date
  11.     Dim time2 As Date
  12.  
  13.     time1 = #12:58:36 PM#
  14.     time2 = #12:10:10 PM#
  15.  
  16.     tArray = Split(time1, ":")
  17.     t1inSecond = tArray(0) * 3600 + tArray(1) * 60 + Split(tArray(2), " ")(0)
  18.  
  19.     tArray = Split(time2, ":")
  20.     t2inSecond = tArray(0) * 3600 + tArray(1) * 60 + Split(tArray(2), " ")(0)
  21.  
  22.     st = t1inSecond + t2inSecond
  23.  
  24.     H = st \ 3600
  25.     M = (st - (H * 3600)) \ 60
  26.     S = st - (H * 3600) - M * 60
  27.     HMS = H & IIf(M < 10, ":0", ":") & M & IIf(S < 10, ":0", ":") & S
  28.     Debug.Print HMS
  29. End Function
  30.  
Oct 12 '10 #4
samvb
228 New Member
Thanks dsatino! I used your method to solving the problem perfectly!

Thank you all!
Oct 12 '10 #5
NeoPa
32,557 Recognized Expert Moderator MVP
samvb:
I used your method to solving the problem perfectly!
I suggest it would be a good idea to set their post as the Best Answer in that case :-)
Oct 12 '10 #6
neelsfer
547 Contributor
I use "long time" to do a similar calculation for finishtime and startime tables
TotalTime: Format([FinishTime]-[starttime],"hh:nn:ss")
Oct 12 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1940
by: Tom Mortimer | last post by:
Hi, A quick question - can anyone tell me how to interpret negative time values in pstats.Stats.print_stats() output? Eg - 39052965 function calls (38035317 primitive calls) in -250.959 CPU...
0
1206
by: Ron Hocking | last post by:
When I link a MySQL table containing a TIME column to Microsoft Access the value does not display. If I edit the value it updates correctly in mysql but if I refresh the Access datasheet view the...
1
2507
by: gi75research | last post by:
What should be a very simple function is going terribly wrong, and I don't know why. StartTime and EndTime are table values (formatted like "01:00A" or "02:00P"); DaypartStart and DaypartEnd are...
4
11666
by: narayana | last post by:
hi gurus, I am kid at DB2 .problem is I am unable to insert values of time and date datatype fields into tables .default date datatype is taking 4bytes lenght so I am unable to insert date value...
1
1695
by: madhura | last post by:
Hi, I need to compare some time values stored in a file in the following format & get the lowest of them. FORMAT - 16:12.433(mins:seconds.milliseconds) Can someone help me with the required...
2
7582
by: dwasbig9 | last post by:
Hi Group (fairly limited knowledge of Access and almost none of Access VBA. Using Access 2003). I need to sum time, I've found through the groups archive an sql extract that led me to this ...
1
2030
by: trevorjhughes | last post by:
I am running an import of some date/time values that have come from a Cognos query. These values are in a CSV file and I want to import them into access. The CSV file would show the value thus:...
4
3765
by: whatsuppussycat | last post by:
I want to be able to SUM the values returned using the TOP 5 and COUNt statements. So far I've tried from many angles and can't get it to work, very frustrating! Here is my code: SELECT TOP 5...
5
7652
by: mabrynda | last post by:
Hi, Is there any possibility to sum all the values in many (say n) columns in a single table using VBA in access 2003? Say I have a table with 200 columns. Say the table name is TableCOUNT and the...
0
7225
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
7326
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,...
1
7046
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
7498
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...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
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
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1558
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 ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.