Date Range Syntax Access 2003

I would like some syntax eamples for Access 2003 for date range queries.

Thanks,

Steve
submarinerssbn731Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
PatHartmanConnect With a Mentor Commented:
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
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
Try this..

SELECT * from TableName WHERE CDATE(ColumnName) between #2016-01-01# and #2016-01-31#
0
 
Gustav BrockConnect With a Mentor CIOCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
submarinerssbn731Author Commented:
Thanks to you both!!!
0
 
Pawan KumarDatabase ExpertCommented:
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
 
Dale FyeConnect With a Mentor Commented:
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
 
submarinerssbn731Author Commented:
Thanks to you all!
0
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
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
 
Gustav BrockCIOCommented:
Using CDate([ColumnName]) is not a typical method used when filtering for a date range.
0
All Courses

From novice to tech pro — start learning today.