?
Solved

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

Posted on 2014-12-11
5
Medium Priority
?
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 120

Accepted Solution

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

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

770 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