Date Range Syntax Access 2003

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


Question by:submarinerssbn731
  • 3
  • 2
  • 2
  • +2
LVL 18

Assisted Solution

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

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

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?


Author Comment

ID: 41828321
Thanks to you both!!!
LVL 18

Expert Comment

by:Pawan Kumar Khowal
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!
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

LVL 47

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.
LVL 34

Accepted Solution

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

Author Comment

ID: 41848915
Thanks to you all!
LVL 18

Assisted Solution

by:Pawan Kumar Khowal
Pawan Kumar Khowal 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 -

Also even if is used it will do the job.

Anyways ! Thanks !
LVL 49

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now