Solved

How query data using date part of a date/time field

Posted on 2014-04-17
2
982 Views
Last Modified: 2014-04-17
In a table I have a date/time field that looks like this for example:

4/16/2014 12:43:41 PM

But I want to query records using just the date part of that information.

My query criteria looks like:

Between [Forms]![frmSelectDatesForLaborTranxReport]![txtStart] And [Forms]![frmSelectDatesForLaborTranxReport]![txtEnd]

But I 'm sure I have to change it somehow to return the records that have 4/16/2014 or whatever date range is entered in frmSelectDatesForLaborTranxReport

How can I do this?

--Steve
0
Comment
Question by:SteveL13
2 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40006657
You can use DateValue:

WHERE DateValue(YourDateField) BETWEEN [Forms]![frmSelectDatesForLaborTranxReport]![txtStart] And [Forms]![frmSelectDatesForLaborTranxReport]![txtEnd]
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40006682
No points please.  I agree with Scott on use of the DateValue ( ), but I don't like using BETWEEN with date fields.  Personally, I would use:

WHERE DateValue([YourDateField]) >= Forms![frmSelectDatesForLaborTranxReport]!txtStart]
AND DateValue([YourDate]) <= Forms![frmSelectDatesForLaborTranxReport]!txtEnd]

Actually, I generally use:

WHERE [YourDateField] >= Forms![frmSelectDatesForLaborTranxReport]!txtStart]
AND [YourDate] < DateAdd("d", 1, Forms![frmSelectDatesForLaborTranxReport]!txtEnd])
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 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