Solved

How can I query time frame from date time field in Access?

Posted on 2014-12-11
5
371 Views
Last Modified: 2015-01-05
I have a database that tracks a  transaction.  I want to be able to write a query that shows when this transaction happens between the hours of 7:00 am and 9:30am each day. I also want to be able to see this week over week as a trend.  I have 3 available fields to use that are date/time related.  I have a "Date/Tm" field that shows "12/2/2014  7:17:12 AM". I have a "Date" field that shows "12/02/2014".  I also have a "Day of the Week" field that shows "Tuesday".  I also have fields for "Employees", "Locations", and "Transactions"

I am envisioning writing a query that could be exported and used in a pivot table to show the employee, the location, and the amount of transactions that occurred each week by day and within the specified time frame. I have attached an example of what I would like to see in the resulting query.

Thanks!
0
Comment
Question by:Dominator1025
  • 3
5 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40494772
you can use

timeValue("12/2/2014  7:17:12 AM")

7:17:12 AM    < result
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40494774
in your query use  timeValue([Date/Tm])
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40494782
you can also use

Timeserial(Hour([Date/Tm]), Minute([Date/Tm]),second([Date/Tm]))
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40494855
You don't realize it yet, but how you are storing your data is screwed
I have 3 available fields to use that are date/time related.  I have a "Date/Tm" field that shows "12/2/2014  7:17:12 AM". I have a "Date" field that shows "12/02/2014".  I also have a "Day of the Week" field that shows "Tuesday".

It is very likely that they are all storing the very same thing.
Access stores DateTimes as a special kind of Double.
The decimal part is always positive and is the fraction of the day
The Integer part represents the day, with Day zero being 30-Dec-1899.

You can format the fields all you like -- but they STORE the same thing

SO

You can throw a calculated field into your query CDbl([Date/Tm]) - CLng([Date/Tm]) and for a criteria, you want that to be BETWEEN 7/24 AND 9.5/24

Then group it however you'd like and pivot it.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40495624
You can use this query with Weekday to obtain a useful sort order:

Select
    Employees,
    Locations,
    [Day of the Week],
    TimeValue([Date/Tm]) As TransactionTime,
    Sum(Transactions) As TotalTransactions
From
    tblYourTable
Group By
    Employees,
    Locations,
    Weekday([Date/Tm]),
    [Day of the Week]

/gustav
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now