Help - Search Date Range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my table i have dates in this format 2/2/83. I need help on making a query
that will allow me to search values in fields given a certain date range. For
example i want a query that will give me all the values from 12/28/82 to
2/2/83.

I have tried something like this:
WHERE Date=[From Date] And Date=[To Date];

but unfortunately i was unsuccessful due to my lack of knowledge in Visual
Basic...

Thanks in advance...
 
You want:

....
WHERE [Date] BETWEEN [From Date] And [To Date]

BTW, "Date" is a bad Field name as "Date" is also a reserved word for the
VBA function Date() (in VBA, "Date" means the function Date()). Suggest you
change the Field name to something else.
 
try this:

where (date >= '12/28/82' and date <= '02/02/83');

Quotemarks are valid delimiters in SQL/Server - but the date delimiter
in Access is #. Replacing the ' with # will work.
In my table i have dates in this format 2/2/83. I need help on making a query
that will allow me to search values in fields given a certain date range. For
example i want a query that will give me all the values from 12/28/82 to
2/2/83.

I have tried something like this:
WHERE Date=[From Date] And Date=[To Date];

Try

Parameters [From Date] Date/Time, [End Date] Date/Time;
SELECT <whatever>
FROM <whereever>
WHERE [Date] BETWEEN [From Date] AND [End Date];

You should consider changing the reserved name Date to some other
fieldname - Access *will* get confused.

John W. Vinson[MVP]
 
Thank you for the clarification.

my date field is in text type. I got a sample size and converted it
to type date/time and tried it one more time like this:

select tabl1.*
from tabl1
where (dateonfile >= #4/15/2005# and dateonfile <= #4/20/2005#)

it worked.


try this:

where (date >= '12/28/82' and date <= '02/02/83');

Quotemarks are valid delimiters in SQL/Server - but the date delimiter
in Access is #. Replacing the ' with # will work.
In my table i have dates in this format 2/2/83. I need help on making a query
that will allow me to search values in fields given a certain date range. For
example i want a query that will give me all the values from 12/28/82 to
2/2/83.

I have tried something like this:
WHERE Date=[From Date] And Date=[To Date];

Try

Parameters [From Date] Date/Time, [End Date] Date/Time;
SELECT <whatever>
FROM <whereever>
WHERE [Date] BETWEEN [From Date] AND [End Date];

You should consider changing the reserved name Date to some other
fieldname - Access *will* get confused.

John W. Vinson[MVP]
 
Thank you for the clarification.

my date field is in text type. I got a sample size and converted it
to type date/time and tried it one more time like this:

select tabl1.*
from tabl1
where (dateonfile >= #4/15/2005# and dateonfile <= #4/20/2005#)

it worked.

Yep. A Text field will NOT work unless you use a yyyy/mm/dd layout,
since the text string '4/15/2005' is "less than" the text string
'4/20/1766', and "greater than" the text string '3/25/2150'.

John W. Vinson[MVP]
 
Back
Top