SQl queries searching by date range

15,293

Solution 1

SELECT * from Table1 WHERE (CDATE(ColumnDate) BETWEEN #03/26/2010# AND #03/19/2010#)
SELECT * from Table1 WHERE (CINT(ColumnAge) between 25 and 40)

Dates are represented in Access between # symbols in #MM/DD/YYYY#. You should really be storing the date as a date field :)

Solution 2

SELECT * from Table1 WHERE ColumnDate between '2010-03-26' and '2010-03-19'
SELECT * from Table1 WHERE ColumnAge between 25 and 40

I don't use Access, so YMMV.

Solution 3

Try converting ColumnDate to actual date/time with CDate function. Conversion to int can be done with CInt, I guess.

I don't use Access, so it's just a common-sense guess.

Share:
15,293
tecno
Author by

tecno

Updated on June 14, 2022

Comments

  • tecno
    tecno almost 2 years

    I have a table in an Access 2007 database. All fields are of type text. Can the following be done using the where clause? If so how?

    • SELECT * from Table1 WHERE (ColumnDate is between 26th and 19th of march 2010)
    • SELECT * from Table1 WHERE (ColumnAge is between 25 and 40)

    The usual < <= operators don't seem to work.

    Thanks,