Solved

Date Range Syntax Access 2003

Posted on 2016-10-04
10
81 Views
Last Modified: 2016-11-08
I would like some syntax eamples for Access 2003 for date range queries.

Thanks,

Steve
0
Comment
Question by:submarinerssbn731
[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
  • 2
  • 2
  • +2
10 Comments
 
LVL 29

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 125 total points
ID: 41828258
Try this..

SELECT * from TableName WHERE CDATE(ColumnName) between #2016-01-01# and #2016-01-31#
0
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 total points
ID: 41828318
Your date field should be of data type Date, thus CDate is not needed. It is simply:

Select * From YourTable Where YourDateField Between #2016/07/01# And #2016/08/31#

Open in new window


Or what do you have in mind?

/gustav
0
 

Author Comment

by:submarinerssbn731
ID: 41828321
Thanks to you both!!!
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41828333
Sir, if you dont need more info on this question, Could you please accept one or more answer as solution and close the question.

Thank you!
0
 
LVL 48

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 125 total points
ID: 41828364
Another issue you need to understand is that if your Date field contains time values as well as the date, then in order to get all of the records for today, it would be best to use a criteria like:

WHERE [YourDateField] >= #2016/09/04# AND [yourDateField] < #2016/09/05#

By default, Access uses the date format "mm/dd/yy" when referring to dates, but the syntax displayed above "yyyy/mm/dd" is more acceptable for international applications.
0
 
LVL 37

Accepted Solution

by:
PatHartman earned 125 total points
ID: 41828534
Since when is a literal a good example?  Do you hard code dates in your queries?

1.  Refer to controls on a form - make sure they are defined as date format:
Where SomeDate Between Forms!yourform!StartDate and Forms!yourform!EndDate

2. Other cfields in the query
Where SomeDate Between StartDate and EndDate

3. Using TempVars (probably not available in A2003)
Where SomeDate Between tvStartDate.Value and tvEndDate.Value
0
 

Author Comment

by:submarinerssbn731
ID: 41848915
Thanks to you all!
0
 
LVL 29

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 125 total points
ID: 41869663
CDATE function to used since we don't know what is the data type of the column. The Author has not mentioned it.

So effectively if the data type if Date then we can remove but if the data type is other than date then we may need to convert it before comparison. We came across many examples where the date is stored as char/Varchar, so thats why CDate is mentioned.

For example - https://www.experts-exchange.com/questions/28979395/Need-help-with-a-query.html?notificationFollowed=178317537#a41863244

Also even if is used it will do the job.

Anyways ! Thanks !
Pawan
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 41875980
Using CDate([ColumnName]) is not a typical method used when filtering for a date range.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

724 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