Solved

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

Posted on 2014-12-11
5
385 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 120

Accepted Solution

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

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

7:17:12 AM    < result
0
 
LVL 120

Expert Comment

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

Expert Comment

by:Rey Obrero (Capricorn1)
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 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