Solved

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

Posted on 2014-12-11
5
368 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
Comment Utility
you can use

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

7:17:12 AM    < result
0
 
LVL 119

Expert Comment

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

Expert Comment

by:Rey Obrero
Comment Utility
you can also use

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

Expert Comment

by:Nick67
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

763 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

10 Experts available now in Live!

Get 1:1 Help Now