473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Count number of Items in a Time/Date Range

39 New Member
I want to count the number of items that occur within a range of time throughout different days.
My original data comes from a machine that logs the time a car passes a point in a road over different days (Traffic Analysis).
I'd like to create a query that would count the number of cars between certain time periods, i.e from 7 to 10, 10 to 14:00 and 14:00 to 21:00 (military time).
Currently the date field is displayed as such
(23.08.2010 10:37:20)
(day, month, year, hour, minute, second)
I have created a seperate table named Data_Range with a the following Columns: Start_Time, End_Time, ID
It would be nice if I could write a query or VB script that would look at the time ranges specified in Data_Range and then give me the resulting count for items within that time range regardless of date.

I'm not sure of the exact SQL syntax but I envision it to be something like this:

SELECT Time from TrafficDataTable, Count* as Number_of_cars WHERE Time_1 is between Start_time and End_Time

Thanks
Miguel
Mar 17 '11 #1
3 5320
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Hi again Miguel

I think you should be able to use TimeValue([Time]) to extract the time part of the date/time field, and then make a query like so:
Expand|Select|Wrap|Line Numbers
  1. SELECT Data_Range.TimeStart, Data_Range.TimeEnd, Count(TrafficDataTable.*) AS NrOfCars
  2. FROM Data_Range, TrafficDataTable
  3. WHERE (((TimeValue(TrafficDataTable.Time)) Between [TimeStart] And [TimeEnd]))
  4. GROUP BY Data_Range.TimeStart, Data_Range.TimeEnd;
  5.  
Mar 17 '11 #2
Miguel Valenzue
39 New Member
Thanks again Smiley.
I had originally tried this:

Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(Datotid) AS BilNumber from tbl_KNIVEVEIEN WHERE (DatePart('h',Datotid) BETWEEN 7 and 19)
  2. UNION
  3. SELECT COUNT(Datotid) AS BilNumber from tbl_KNIVEVEIEN WHERE (DatePart('h',Datotid) BETWEEN 19 and 23)
  4. UNION
  5. SELECT COUNT(Datotid) AS BilNumber from tbl_KNIVEVEIEN WHERE (DatePart('h',Datotid) BETWEEN 23 and 7)
  6. UNION
  7. SELECT COUNT (Datotid) AS BilNumber from tbl_KNIVEVEIEN;
  8.  
using DatePart.
The interesting thing is that when I go from 23 to 7, it counts from 7 to 23, so I'll have to probably do some ranges that stay within the 24 hour increments and then add them or something.
Mar 17 '11 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I think maybe you could try instead of:
Expand|Select|Wrap|Line Numbers
  1. BETWEEN StartTime and EndTime
to use
Expand|Select|Wrap|Line Numbers
  1. Time>StartTime AND Time<EndTime
Mar 17 '11 #4

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

Similar topics

8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
3
by: rugger81 | last post by:
I am currently working in the sql server 2000 environment and I want to write a function to pull all dates within a given date range. I have created several diferent ways to do this but I am...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
1
by: flumpuk | last post by:
Hi My job currently requires me to enter data from 300+ forms a month. The system which we used in Excel was slow , and theprevious guy had three workbooks for this job . I have created...
3
by: kmnotes04 | last post by:
Could anyone tell me how to restrict the date range for items that appear on a report? Old items from previous years appear on the report. I was asked to have only this year's items (and beyond)...
0
by: mwalsh62 | last post by:
Greetings all! My first post here, and my mind is pudding at this point (any flavor you like)! I have been searching for days, and still can't figure out the proper syntax that I require. This...
5
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix,...
1
by: yanivt | last post by:
working on a seemingly simple problem, but for some reason it is giving me a bit of a hard time. I have a table with the following fields: FileID, FName, FPath, DateCreated, Owner. It is a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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
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...
1
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.