473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query sun of time fields

4 New Member
I'm new to acess and working on my first db. I haven't started using code yet so i still working with wizards. I am using Acess 2000 on an Windows XP.
My problem is i have a time field that i need too run a query on and the sum needs to be in hundreds of hours but i've tried everything and as soon as the sum gets to 23:59 it starts over at 0:00. I need this to show large hours numbers
Nov 17 '06 #1
19 3204
kds14589
4 New Member
oooooooooookkkk kkkkkkkkkkkk
Nov 17 '06 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
I'm new to acess and working on my first db. I haven't started using code yet so i still working with wizards. I am using Acess 2000 on an Windows XP.
My problem is i have a time field that i need too run a query on and the sum needs to be in hundreds of hours but i've tried everything and as soon as the sum gets to 23:59 it starts over at 0:00. I need this to show large hours numbers
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Field1, Field2, 
  3. CInt(Sum([TimeField])) * 24 +  Hour(Sum([TimeField]) As TotalHours,
  4. Minute(Sum([TimeField])) As Mins
  5. FROM Tablename
  6. GROUP BY Field1, Field2;
  7.  
  8.  
Nov 17 '06 #3
NeoPa
32,564 Recognized Expert Moderator MVP
Or a slightly modified version :
Expand|Select|Wrap|Line Numbers
  1. SELECT Field1, Field2, 
  2.     Int(Sum([TimeField])) * 24 + Hour(Sum([TimeField]) As TotalHours, 
  3.     Minute(Sum([TimeField])) As Mins
  4. FROM Tablename
  5. GROUP BY Field1, Field2
Not just for fun - CInt rounds as it goes. Int() truncates, as is required here.
Nov 17 '06 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
Or a slightly modified version :
Expand|Select|Wrap|Line Numbers
  1. SELECT Field1, Field2, 
  2. Int(Sum([TimeField])) * 24 + Hour(Sum([TimeField]) As TotalHours, 
  3. Minute(Sum([TimeField])) As Mins
  4. FROM Tablename
  5. GROUP BY Field1, Field2
Not just for fun - CInt rounds as it goes. Int() truncates, as is required here.
Believe it or not, I originally had it as an Int but changed my approach a couple of times and ended up with CInt. I never remember the rules anyway. Have to go look them up on a regular basis. My mind is like a sieve.

Mary
Nov 17 '06 #5
kds14589
4 New Member
Thanks Neopa and mmccarthy
I’m still having trouble with this one. I never used code before so be patient. After this database is finished this week I’ll learn more about code.
I have a table called [PTP Vehical daily log] (don’t mind the misspelling)
I have three fields in it [start time], [end time], and [night time].
I need to subtract the [start time] from the [end time] then add the [night time] to this total.
Finally I need a grand total in hours that will not roll over at 23:59 like it does.
I tried to follow your example but I keep getting a ‘snytax error (missing operative)’.Wha t I came up with is below.
I would appreciate any help you can give and I promise if I can get this working I wont bother you anymore!!!!!!!! !!!


SELECT
CInt(Sum(([PTP Vehical daily log]![end time]-[PTP Vehical daily log]![start time])+[PTP Vehical daily log]![night time]) * 24 + Hour(Sum(([PTP Vehical daily log]![end time]-[PTP Vehical daily log]![start time])+[PTP Vehical daily log]![night time])) AS TotalHours, Minute(Sum(([PTP Vehical daily log]![end time]-[PTP Vehical daily log]![start time])+[PTP Vehical daily log]![night time])) AS Mins
FROM [PTP Vehical daily log]
GROUP BY [PTP Vehical daily log].[start time], [PTP Vehical daily log].[end time], [PTP Vehical daily log].[night time]
Nov 20 '06 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
OK try this, the group by is only needed if you want your results broken out over something like EmployeeID. I think the main problem was a misplaced bracket.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT (Int(Sum(([end time] - [start time]) + [night time])) * 24 
  3. + Hour(Sum(([end time] - [start time]) + [night time])) AS TotalHours, 
  4. Minute(Sum(([end time] - [start time]) + [night time])) AS Mins
  5. FROM [PTP Vehical daily log];
Nov 20 '06 #7
kds14589
4 New Member
It Worked

Thanks
Nov 20 '06 #8
MMcCarthy
14,534 Recognized Expert Moderator MVP
It Worked

Thanks
No Problem
Nov 20 '06 #9
NeoPa
32,564 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. SELECT Sum([end time] - [start time] + [night time]) AS TotTime, _
  2.     Int(TotTime) * 24 + Hour([TotTime]) AS TotalHours, _
  3.     Minute([TotTime]) AS Mins
  4. FROM [PTP Vehical daily log];
Bear in mind, unless you want this across the whole recordset, you'll need a GROUP BY clause.
This is fundamentally the same as Mary's code.
The advantage is the complicated field is worked out just the once (in the code - Mary's would also be worked out once at execution) and then reused more ligibly. It also introduces a useful concept available in SQL.
I hope this makes sense.
Nov 20 '06 #10

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

Similar topics

6
29928
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access newsgroups, the access support centre, I can seem to find no similar situation. I am not using any references, or VBA at all in the first place....
6
17143
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how this can be done? I've tried setting the default value of the text fields on the form to be equal to ! using Access' expression
8
3701
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: "Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21"...
2
3142
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong) ..Fields.Append .CreateField(strTmpIDFld, dbLong) ..Fields.Append .CreateField(strTmpDateFld, dbDate) ..Fields.Append .CreateField(strTmpDataFld,...
4
3702
by: Macroman | last post by:
MS Access XP, running on Win XP, Processor 2.4Ghz , 512Mb RAM, 40Gb Hard drive Table 1 has 167,000 records and contains the following fields tblone_custID tblone_easting tblone_northing Table 2 has 423,000 records and contains the following fields tbltwo_custID
1
1862
by: commodityintelligence | last post by:
Greetings, I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming training. I will explain my structure before asking my questions. I have data from a table (updated monthly by adding the most current month’s data)...
4
2031
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice with MS Access and VBA. I desperately need help with 2 queries that I am trying to put together. I want to thank anyone that can help me out with...
5
2058
by: DeanL | last post by:
Hi all, I'm trying to set up a query that runs from a command button on a form (simple enough so far), what I want the query to do is take values from the fields on the form (seven fields in total) but sometimes not all the fields will be filled. If a field is empty then the assumption is that no filter will be applied to that field in the...
3
2056
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few parameters...." I have read many articles on the web about how to make a dynamic report based on a cross-tab query. But for some reason mine never...
9
3617
by: Sinner | last post by:
Hi, I have a field name 'USER' in tableMAIN. How do I replace the user names with corresponding user names. I can do that in xl using vlookup but now I'm trying to find a way to do that in access. For a user mismatch, it should give NA Thx.
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7967
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5097
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1953
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 we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.