Solved

Date Range Syntax Access 2003

Posted on 2016-10-04
10
70 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
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 28

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 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?

/gustav
0
 

Author Comment

by:submarinerssbn731
ID: 41828321
Thanks to you both!!!
0
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.

 
LVL 28

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 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.
0
 
LVL 35

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 28

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 49

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

840 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